Jump to content

Recommended Posts

preg_replace( '#width="([^/\.]+)"#', 'width="100%"', $flv);

 

$flv: width="600" height="438" id="veohFlashPlayerEmbed" name="veohFlashPlayerEmbed"></embed></p>

 

preg_replace replace "width="600" " to "width=100%" the problem is... it erases " height="438" id="veohFlashPlayerEmbed" name="veohFlashPlayerEmbed""

Link to comment
https://forums.phpfreaks.com/topic/228604-preg-replace-erasing-other-words/
Share on other sites

Okay so basically what is happening is your negative character class consumes anything that is not a forward slash or a dot, so it matches all the way up to that "/" in the "</embed>" and then it starts backtracking, giving up characters in the match, until it finds the last " it ran into, to satisfy that " you end your pattern with. 

 

Since you are replacing the value of width, and since the value is delimited by quotes, you should make your negative character class match for anything that is not a quote:

 

preg_replace( '#width="([^"]+)"#', 'width="100%"', $flv);

 

This will make it stop matching at the next " it finds.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.