Forum Moderators: coopster

Message Too Old, No Replies

Replacing parts of my string

         

ntbgl

7:11 pm on May 17, 2009 (gmt 0)

10+ Year Member



I have a variable called $text.

$text might contain one or multiple substrings that look like:

<mytag alt="Something here">Something else here</mytag>

What I would like to do is to grab these parts and replace them, with something like:

<div class="xyz">
<object>
<param name="movie" value="http://www.example.com/Something else here"></param>
<param name="wmode" value="transparent"></param>
<embed src="http://www.example.com/Something else here" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350">
</embed></object>
<div class="zyx">Something here</div></div>

How can I go about doing this? Thanks

enigma1

9:41 am on May 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



you need to have some fixed placeholders so you can perform a search/replace on the fly. Check the examples on php.net of the str_replace function:

eg:
// Provides: <body text='black'>
$bodytag = str_replace("%body%", "black", "<body text='%body%'>");
.........