3v4l.org

run code in 300+ PHP versions simultaneously
<?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 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
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"

preferences:
209.91 ms | 407 KiB | 316 Q