/    Sign up×
Community /Pin to ProfileBookmark

advanced str_replace – PLEASE HELP

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><[B]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>[/B]<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.

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@chestertbJul 23.2007 — you could use explode() rather than str_replace()

try this...

[code=php]$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 [/code]


CTB
Copy linkTweet thisAlerts:
@rapidzauthorJul 23.2007 — 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 [B]http://www.dailymotion.com/swf/4H4mn2laITvkFazuS[/B] and discard the rest?
Copy linkTweet thisAlerts:
@rapidzauthorJul 25.2007 — anyone???
Copy linkTweet thisAlerts:
@MrCoderJul 25.2007 — [code=php]
$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);
[/code]
Copy linkTweet thisAlerts:
@rapidzauthorJul 25.2007 — 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?
Copy linkTweet thisAlerts:
@MrCoderJul 25.2007 — 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?[/QUOTE]


I replied here
×

Success!

Help @rapidz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...