johnuk
June 29, 2012, 1:25pm
1
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!!
johnuk
June 29, 2012, 1:37pm
2
I thought id found a solution but havent, so still open to any help
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 =
<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>
The method is:
get the basic string.
save the last part of the string starting at “type=” to a new string $finish
make a $new start string
add the $new start string to the $finish string