Jump to content

embade youtube link using REGEXP


zetcoby

Recommended Posts

hi guys, i am trying to create a button that when u press if in the text are will appear <video>...</video> i know this is js do don't worry i will manage to do it, my problem is in php, i did a function that recognizes the link between <video>...</video> and then it embades it and shows me a youtube video instead, the problem i got is that if i have in the text area more <video>...</video>, like:    bla bla bal<video>youtube link</video> and the other vid <video>youtube link</video> i dont know how to make it embade both, i dont know how to check if there is more, and the second problem i got is that all the text that was not betwen <video>...</video> will disapear after the vide is embadded, here is the code i done until now

<form action="test1.php" method = "POST">	
<textarea name="body" id="text" cols="30" rows="10"></textarea>
<input type="submit" value = "submit">
</form>
<?php 
function video($string){
preg_match_all("#<video\b[^>]*>(.*?)</video>#", $string, $output);
preg_match_all("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+(?=\?)|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $output[0][0], $match); 
return "<iframe width='560' height='315' src='http://www.youtube.com/embed/".$match[0][0]."' frameborder='0' allowfullscreen></iframe>";
} 
if (isset($_POST['body'])&&!empty($_POST['body'])) {
	$body = $_POST['body'];
	print_r(video("$body"));
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.