Jump to content

Preg_replace Problem


traxionn
 Share

Recommended Posts

Hey all,i'm looking for a link (

for example ) converting into a emb video ( of html code). Now i've found online a working script but it's with preg_match_all, and i need to have it working with preg_replace because i need to print to the code in some other part of the script.After a hour google and trying 101 stuffs.. i cant get the preg_replace working correctly. Even simple stuff i cant get working :SNow i've got 2 questions1: can somebody rewrite the code for me, so i can use it on mine website2: can somebody give me a clear explination about the preg_replace so that is can do it in the future on my ownAlready thnx for the replays
<?php$input = "bla die bla[url="http://youtube.com/watch?v=QksqWRqEfy0"]http://youtube.com/watch?v=QksqWRqEfy0[/url]bla die bla";preg_match_all('#(http://www.youtube.com)?/(v/([-|~_0-9A-Za-z]+)|watch\?v\=([-|~_0-9A-Za-z]+)&?.*?)#i',$input,$output);foreach ($output[4] AS $video_id) {	if (!isset($video[$video_id])) {	$video[$video_id]=true;	$embed_code = '<object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/'.$video_id.'&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"> </param><param name="allowscriptaccess" value="always"></param> <embed src="http://www.youtube.com/v/'.$video_id.'&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed></object>';echo $embed_code.'<br>';		}	}?>

Edited by traxionn
Link to comment
Share on other sites

Here are the descriptions for preg_match_all and preg_replace:http://www.php.net/manual/en/function.preg-match-all.phphttp://www.php.net/manual/en/function.preg-replace.phpInstead of doing preg_replace, you could also get all of the matches and then use str_replace to replace each one. That's less efficient, but another possibility.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...