Find and replace values in string

hey guys,

  This may seem like a no-brainier, but the thing is I wont know the length of the string in advance. My client has a pre-made/bought Blog which adds youtube videos into posts via its CMS - basically I want my function to search  a string like the following:

<embed width=“425” height=“344” type=“application/x-shockwave-flash” pluginspage=“http://www.macromedia.com/go/getflashplayer” src=“http://www.youtube.com/somevid”></embed>

and regardless of the current width and height values, I want to replace them with my own constants e.g width=“325” height=“244”. Could someone kindly explain the best way to go about this?

Many thanks in advance!!

I thought id found a solution but havent, so still open to any help :slight_smile:

Try this:



$original =
<embed width="425" height="344" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://www.youtube.com/somevid"></embed>

$finish = type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://www.youtube.com/somevid">

$new = <embed width="12345" height="6789"

$new = $new . $finish =
<embed width="12345" height="6789" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://www.youtube.com/somevid"></embed>


output:

$original =
&lt;embed width="425" height="344" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://www.youtube.com/somevid"&gt;&lt;/embed&gt;

finish = type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://www.youtube.com/somevid"&gt;

$new = &lt;embed width="12345" height="6789"

$new = $new . $finish =
&lt;embed width="12345" height="6789" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://www.youtube.com/somevid"&gt;&lt;/embed&gt;

The method is:

  1. get the basic string.
  2. save the last part of the string starting at “type=” to a new string $finish
  3. make a $new start string
  4. add the $new start string to the $finish string