Vin Vin - 1 year ago 108
PHP Question

Str_replace solution needed

Currently I'm running into an issue, I'm parsing some data from a website and the image urls it returns have different resolution values at the end of them examples being as following..


Currently I am using this method of removing one of them.

$image = $html2->find('meta[property=og:image]',0);
$image = $image->content;

$img = str_replace('-500x330', '', $image);

How could I use a similar method, to remove ALL of the resolution possibilities?

Answer Source
$img = preg_replace('/-\d{3}x\d{3}/', '', $image);

But if you have and two/one digits then pattern must be:

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