fork download
  1. <?php
  2.  
  3.  
  4. $content = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna https://w...content-available-to-author-only...e.com/watch?v=wxsV37GY1IU&feature=share aliqua. Ut enim ad minim veniam, <img src="http://www.google.com/images/logo.gif"> quis nostrud exercitation ullamco https://w...content-available-to-author-only...e.com/watch?v=wxsV37GY1IU&feature=share laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui http://y...content-available-to-author-only...u.be/wxsV37GY1IU officia deserunt mollit anim id est laborum.';
  5.  
  6.  
  7. $urlRegex = "~(?:https?://|\s)[-a-z0-9]+(?:\.[-a-z0-9]+)*(?:\.[a-z]{2,4})(?:/+[-a-z0-9_.:;]*)*(?:\?[-&%|+a-z0-9_=,.:;]*)?(?:[-&%|+&a-z0-9_=,:;.]*)(?:[-!#/&%|+a-z0-9_=,:;.]*)}*~i";
  8. $imageRegex = '<img(.*?)src=("|\')(.+?)(gif|jpg|png|bmp)("|\')(.*?)(/)?>(</img>)?';
  9. $imagePrefixRegex = "/\.(jpg|png|gif|bmp)$/i";
  10. $pattern_youtube = '\bhttps?://(?:www\.)?(?:youtube\.com/[-A-Z0-9]*?(?:\?|&)v=|youtu\.be/)([-A-Z0-9]{11})[-A-Z0-9&=]*?(?=\s|$)';
  11.  
  12.  
  13.  
  14.  
  15. $callback_function = function($m) use ($imageRegex, $pattern_youtube) {
  16.  
  17. print "<PRE><FONT COLOR=ORANGE>"; print_r($m); print "</FONT></PRE>";
  18.  
  19. if (preg_match('~'.$pattern_youtube.'~i', $m[0])) {
  20. print "\nA STUNNING NEW YOUTUBE MATCH WAS FOUND\n\n";
  21.  
  22. //$graph = OpenGraph::fetch($m[1]);
  23. //$replacement = '[![img](http://i...content-available-to-author-only...e.com/vi/$m[1]/0.jpg)](http://y...content-available-to-author-only...u.be/$m[1] "'.$graph->title.'"){#$m[1] .ytmarkdown}';
  24. $graph = '<FONT COLOR=RED>'.$m[10].'</FONT>';
  25. $replacement = "\n\n[![img](http://i...content-available-to-author-only...e.com/vi/".$m[10]."/0.jpg)](http://y...content-available-to-author-only...u.be/".$m[10]." \"".$graph."\"){#".$m[10]." .ytmarkdown}";
  26.  
  27. }
  28. else {
  29. print "\nNO YOUTUBE MATCH FOUND - LET'S PROCESS THE IMAGE\n\n";
  30. $replacement = "\n\n<FONT COLOR=BLUE>BUBBA GUMP</FONT>";
  31. }
  32.  
  33. return $replacement;
  34.  
  35. };
  36.  
  37.  
  38.  
  39. //$content = preg_replace_callback('~('.$imageRegex.'|'.$pattern_youtube.')~i', $callback_function, $content);
  40. //print $content;
  41.  
  42.  
  43. print link_to_opengraph($content, $callback_function, $imageRegex, $pattern_youtube);
  44.  
  45.  
  46. function link_to_opengraph($content, $callback_function, $imageRegex, $pattern_youtube) {
  47.  
  48.  
  49. //$title = 'Project Gooseberry - Why should you contribute to it?';
  50.  
  51. //$graph = OpenGraph::fetch($star);
  52. $content = preg_replace_callback('~('.$imageRegex.'|'.$pattern_youtube.')~i', $callback_function, $content);
  53.  
  54. return $content;
  55.  
  56. }
  57.  
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
<PRE><FONT COLOR=ORANGE>Array
(
    [0] => https://w...content-available-to-author-only...e.com/watch?v=wxsV37GY1IU&feature=share
    [1] => https://w...content-available-to-author-only...e.com/watch?v=wxsV37GY1IU&feature=share
    [2] => 
    [3] => 
    [4] => 
    [5] => 
    [6] => 
    [7] => 
    [8] => 
    [9] => 
    [10] => wxsV37GY1IU
)
</FONT></PRE>
A STUNNING NEW YOUTUBE MATCH WAS FOUND

<PRE><FONT COLOR=ORANGE>Array
(
    [0] => <img src="http://www.google.com/images/logo.gif">
    [1] => <img src="http://www.google.com/images/logo.gif">
    [2] =>  
    [3] => "
    [4] => http://www.google.com/images/logo.
    [5] => gif
    [6] => "
    [7] => 
)
</FONT></PRE>
NO YOUTUBE MATCH FOUND - LET'S PROCESS THE IMAGE

<PRE><FONT COLOR=ORANGE>Array
(
    [0] => https://w...content-available-to-author-only...e.com/watch?v=wxsV37GY1IU&feature=share
    [1] => https://w...content-available-to-author-only...e.com/watch?v=wxsV37GY1IU&feature=share
    [2] => 
    [3] => 
    [4] => 
    [5] => 
    [6] => 
    [7] => 
    [8] => 
    [9] => 
    [10] => wxsV37GY1IU
)
</FONT></PRE>
A STUNNING NEW YOUTUBE MATCH WAS FOUND

<PRE><FONT COLOR=ORANGE>Array
(
    [0] => http://y...content-available-to-author-only...u.be/wxsV37GY1IU
    [1] => http://y...content-available-to-author-only...u.be/wxsV37GY1IU
    [2] => 
    [3] => 
    [4] => 
    [5] => 
    [6] => 
    [7] => 
    [8] => 
    [9] => 
    [10] => wxsV37GY1IU
)
</FONT></PRE>
A STUNNING NEW YOUTUBE MATCH WAS FOUND

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna 

[![img](http://i...content-available-to-author-only...e.com/vi/wxsV37GY1IU/0.jpg)](http://y...content-available-to-author-only...u.be/wxsV37GY1IU "<FONT COLOR=RED>wxsV37GY1IU</FONT>"){#wxsV37GY1IU .ytmarkdown} aliqua. Ut enim ad minim veniam, 

<FONT COLOR=BLUE>BUBBA GUMP</FONT> quis nostrud exercitation ullamco 

[![img](http://i...content-available-to-author-only...e.com/vi/wxsV37GY1IU/0.jpg)](http://y...content-available-to-author-only...u.be/wxsV37GY1IU "<FONT COLOR=RED>wxsV37GY1IU</FONT>"){#wxsV37GY1IU .ytmarkdown} laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui 

[![img](http://i...content-available-to-author-only...e.com/vi/wxsV37GY1IU/0.jpg)](http://y...content-available-to-author-only...u.be/wxsV37GY1IU "<FONT COLOR=RED>wxsV37GY1IU</FONT>"){#wxsV37GY1IU .ytmarkdown} officia deserunt mollit anim id est laborum.