Click to See Complete Forum and Search --> : advanced str_replace - PLEASE HELP


rapidz
07-23-2007, 04:26 AM
Ok, basically, i'm creating a CMS for a client.

At the moment they're uploading the video through dailymotion, and grabbing the embed code.

They enter the embed code into a field in the CMS, and i want my cms to be able to delete everything after a certain tag.

Here is the code that dailymotion give you:

<div><object width="425" height="335"><param name="movie" value="http://www.dailymotion.com/swf/6TMx6A6bDKSlyikB7"></param><param name="allowfullscreen" value="true"></param><embed src="http://www.dailymotion.com/swf/6TMx6A6bDKSlyikB7" type="application/x-shockwave-flash" width="425" height="335" allowfullscreen="true"></embed></object><br /><b><a href="http://www.dailymotion.com/video/x2ln7h_gagner-de-l-argent-en-restant-chez_videogames">GAGNER DE L ARGENT EN RESTANT CHEZ SOI</a></b><br /><i>Uploaded by <a href="http://www.dailymotion.com/zdax6">zdax6</a></i></div>


but all i want to be entered is:

<object width="425" height="335"><param name="movie" value="http://www.dailymotion.com/swf/6TMx6A6bDKSlyikB7"></param><param name="allowfullscreen" value="true"></param><embed src="http://www.dailymotion.com/swf/6TMx6A6bDKSlyikB7" type="application/x-shockwave-flash" width="425" height="335" allowfullscreen="true"></embed></object>


I'm wondering if this is at all possible. So that once it see's the closing <object> tag, it will cut off everything after it.

Any assistance would be much much appreciated.


Many thanks,

Rapidz.

chestertb
07-23-2007, 07:51 AM
you could use explode() rather than str_replace()

try this...

$cut = explode("</object>", $dailymotion); //splits the string into array elements. in this case, element [0] contains everything before '</object>' and element [1] contains everything after.

$cut[0] .= "</object>"; //puts the object tag

CTB

rapidz
07-23-2007, 08:24 AM
nope i'm afraid that didn't work either :(.

Is there any way i can just take the src string from the embed code. That way i can put that src in a variable and add it to a premade variable.


In other words, how can i get the http://www.dailymotion.com/swf/4H4mn2laITvkFazuS and discard the rest?

rapidz
07-25-2007, 04:12 AM
anyone???

MrCoder
07-25-2007, 05:40 AM
$text = '<div><object width="425" height="335"><param name="movie" value="http://www.dailymotion.com/swf/6TMx6A6bDKSlyikB7"></param><param name="allowfullscreen" value="true"></param><embed src="http://www.dailymotion.com/swf/6TMx6A6bDKSlyikB7" type="application/x-shockwave-flash" width="425" height="335" allowfullscreen="true"></embed></object><br /><b><a href="http://www.dailymotion.com/video/x2ln7h_gagner-de-l-argent-en-restant-chez_videogames">GAGNER DE L ARGENT EN RESTANT CHEZ SOI</a></b><br /><i>Uploaded by <a href="http://www.dailymotion.com/zdax6">zdax6</a></i></div>';

echo preg_replace("/.*?value=\"(.*?)\".*/si", "$1", $text);

rapidz
07-25-2007, 06:40 AM
MrCoder, thanks a lot.

The code works PERFECTLY when i test it locally, but when i test it online, it doesn't work. It displays the full code (<div><object....) instead of the embed key.

I can't understand how the EXACT same peice of code can work locally on my test server, but not work online! Any suggestions?

MrCoder
07-25-2007, 02:25 PM
MrCoder, thanks a lot.

The code works PERFECTLY when i test it locally, but when i test it online, it doesn't work. It displays the full code (<div><object....) instead of the embed key.

I can't understand how the EXACT same peice of code can work locally on my test server, but not work online! Any suggestions?

I replied here (http://www.webdeveloper.com/forum/showthread.php?p=782691#post782691)