Vin Vin - 1 month ago 17
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..

-500x330
and
-660x330
.

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
$img = preg_replace('/-\d{3}x\d{3}/', '', $image);

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

/-\d{1,3}x\d{1,3}/
Comments