Sam Skirrow Sam Skirrow - 1 year ago 87
PHP Question

PHP replace the very last part of a url

I have the following url - this url is not always the same though, but will always end the same:

$thumbnail_url = ''

using php I'd like to replace

so the new thumbnail would look something like this:

$hq_thumbnail_url = ''

Is this possible?

Answer Source

str_replace() is probably your most simple approach...

$thumbnail_url = '';

$hq_thumbnail_url = str_replace('hqdefault.jpg', 'maxresdefault.jpg', $thumbnail_url);

Hope this helps!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download