- preg_replace: documentation ( source)
<!DOCTYPE html>
<html>
<head><title>some title</title></head>
<body>
<form method="post" action="">
<input type="text" name="something"/>
<input type="submit" value="click" name="submit" />
</form>
<?php
if(isset($_POST['submit'])) {
$text = $_POST ['something'];
$replaced = preg_replace('#https://www\.youtube\.com/watch\?v=(\w+)[^\s]+#i','<iframe width="853" height="480" src="http://www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>',$text);
echo $replaced ;
}
?>
</body>
<html>