I've got a bunch of entries in a database like this
<object><embed src="http://www.flashgamesnexus.com/gamefiles/gemcraft/gemcraft.swf" width="640" height="480"></object></center>
I want to replace them all so it looks more like this:
<object><embed src="http://www.flashgamesnexus.com/gamefiles/gemcraft/gemcraft.swf" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" / width="640" height="480"></object></center>
Its basically the same on every entry. Just need to insert some text in the middle. How would I do this in PHP and regular expressions?
I would simply do a string_replace if it doesn't require any complicated logic.
str_replace('<embed', '<embed type="application/x-shockwave-flash" and_anything_else_you_want_added ', $string)
Make sure there is a space after what's added, like I did.
Also although this might be off-topic, you really shouldn't store HTML like that, because you run into maintenance issues like this. HTML should be generated as part of the display. The only real exception is if it takes heavy processing power and you need to cache the HTML, in which case you store the raw data (so it's easy to regenerate the HTML) with the cached (so it's quicker to output).
Yeah, I know, its not very convenient on these update issues but its also a lot more flexible to store HTML at times rather than generate.
This topic is now closed. New replies are no longer allowed.