Reputation: 287
I'm not an expert with Regex, but I'm trying to convert an image URL to another and delete the height and width attributes...
$content = preg_replace('/src="([^"]*)(png|jpeg|jpg|gif|bmp)"/', 'src="http://www.mysite.com/thumb.php?url=$1&width=500&height=500"', $post_content);
$content = preg_replace( '/(width|height)=\"\d*\"\s/', "", $content);
echo $content;
Echoing the results doesn't give me an image extension:
<img src="http://www.mysite.com/thumb.php?url=http://www.mysite.com/wp-content/uploads/2013/02/image.&width=500&height=500" />
How can I do this?
Upvotes: 0
Views: 192
Reputation: 27525
The $1
in your replacement-string refers to the first capturing group of your regex. In other words, the value of $1
is the character sequence matched by the first (...)
in the regex.
The problem is, your first set of parentheses does not include file extensions - hence the missing filename extension in the result.
Upvotes: 2