violinrocker Posted February 23, 2011 Share Posted February 23, 2011 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"" Quote Link to comment https://forums.phpfreaks.com/topic/228604-preg-replace-erasing-other-words/ Share on other sites More sharing options...
.josh Posted February 23, 2011 Share Posted February 23, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/228604-preg-replace-erasing-other-words/#findComment-1178708 Share on other sites More sharing options...
violinrocker Posted February 23, 2011 Author Share Posted February 23, 2011 ohhhh Tnx for telling me that! Quote Link to comment https://forums.phpfreaks.com/topic/228604-preg-replace-erasing-other-words/#findComment-1178717 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.