ClarkeRubber

silly regex

May 20th, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.49 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]+))#';
  4.     $pattern[1] = '#(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=\"$&\" target=\"_blank\">$&</a>";
  7.     $body = preg_replace($pattern, $replacement, $body);
  8.     echo $body;
  9. }
Advertisement
Add Comment
Please, Sign In to add comment