Replace height="***" stars
I want to replace 'width' and 'height' on my site.
For example:
width="600" height="365"
I want to change the width and height, to
width="712" height="475"
I can do this with.
$replace =str_replace('width="600" height="365"', 'width="712" height="475"', $replace)
The problem is, the width and height is not always 600 and 365 they might be something else. like.
width="222" height="333"
Anythin开发者_高级运维g... I'm looking for something like this:
$replace =str_replace('width="***" height="***"', 'width="712" height="475"', $replace)
That replaces anything inside the width and height to '712' and '475'.
Anyone has any idea how to can be done? Thanks!
$replace = preg_replace('~width="\d*" height="\d*"~', 'width="712" height="475"', $replace);
While you're better off setting the width and height once programmatically in your PHP, you can use a regular expression to find and replace it later if you must.
$replace = preg_replace('/width="\d+" height="\d+"/', 'width="712" height="475"', $replace);
精彩评论