ClarkeRubber

grrr

May 20th, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.52 KB | None | 0 0
  1. <?php
  2. if($body = stripslashes($_POST['body'])){
  3.     $pattern[0] = '#(http:\/\/)?(www.)?(youtube\.com\/watch\?v[=]([a-zA-Z0-9_]+))&[0-9a-zA-Z=_]*#';
  4.     $pattern[1] = '#((?!.*com/embed.*)(http:\/\/)?(www.)?[0-9a-zA-Z]+\.[a-zA-Z]+((\/[0-9a-zA-Z]*)*(\?(&*\w+[=]\w+))*)?)#';
  5.     $replacement[0] = '<iframe width="560" height="315" src="http://www.youtube.com/embed/$4" frameborder="0" allowfullscreen></iframe>';
  6.     $replacement[1] = '<a href="$1" target="_blank">$1</a>';
  7.     $body = preg_replace($pattern, $replacement, $body);
  8.     echo $body;
  9. }
Advertisement
Add Comment
Please, Sign In to add comment