[Solved] How to strip parts of the given url using preg_replace (php) [closed]


For this specific case, you don’t need a regular expression, you can just parse the url

$url="http://dev.time.com/wp-content/uploads/2014/08/sheep-shrek-300x199.jpg?w=360";
$parts = parse_url($url);
echo $parts['host'] . $parts['path'];

Missed that you want to strip the size …

$data = preg_replace('/(-\d+x\d+)\.jpg/', '.jpg', $data);

1

solved How to strip parts of the given url using preg_replace (php) [closed]