3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $string = '<u>\\n\\\\*HYPERLINK \\"http://www.youtube.com/watch?v=A0VUsoeT9aM\\"A Youtube Video</u>'; $pattern = '/http[?.:=\w\d\\/]*/'; $namePattern = '/(?:")([\s\w]*)</'; preg_match($pattern, $string, $matches); preg_match($namePattern, $string, $nameMatches); print "original output:\n"; var_dump($matches[0]); var_dump($nameMatches[1]); print "\n"; $newString = 'Blablabla Beginning Text <u>\\n\\\\*HYPERLINK \\"http://www.youtube.com/watch?v=A0VUsoeT9aM\\"1.A Youtube Video</u> blablabla Text Middle <u>\\n\\\\*HYPERLINK \\"http://www.youtube.com/watch?v=A0VUsoeT9aM\\"2. A Youtube Video</u> blabla Text after'; $newpattern = '/(http[?.:=\w\d\\/]*)\\\\"([\s\w]*)/'; print "does the new pattern work?\n"; preg_match($newpattern, $newString, $allMatches); var_dump($allMatches); print "yep.\n"; $newReplace = '<a href="\\1">\\2</a>'; var_dump( preg_replace($newpattern, $newReplace, $newString) );
Output for 4.3.0 - 7.1.0
original output: string(42) "http://www.youtube.com/watch?v=A0VUsoeT9aM" string(15) "A Youtube Video" does the new pattern work? array(3) { [0]=> string(45) "http://www.youtube.com/watch?v=A0VUsoeT9aM\"1" [1]=> string(42) "http://www.youtube.com/watch?v=A0VUsoeT9aM" [2]=> string(1) "1" } yep. string(263) "Blablabla Beginning Text <u>\n\\*HYPERLINK \"<a href="http://www.youtube.com/watch?v=A0VUsoeT9aM">1</a>.A Youtube Video</u> blablabla Text Middle <u>\n\\*HYPERLINK \"<a href="http://www.youtube.com/watch?v=A0VUsoeT9aM">2</a>. A Youtube Video</u> blabla Text after"