3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function tagify($str, $baseUrl = '/board/') { $baseUrl = rtrim($baseUrl, '/'); return preg_replace('/ (?!<a[^<>]*>[^\#]*) # Dont match if there is an opening <a> tag and any chars after it. \#([-_\w]+\b) # Match the hashtag. (?![^<]*<\/a>) # Ignore any anding </a> tag including any chars before it not in hashtag. /ix', '<a href="'.$baseUrl.'/$1">#$1</a>', $str); } $str = <<<STR This is <a href="http://foo.com">This is #foo</a>. Simple #html-stuff text <a href="http://foobar.com#baz">#simple</a> <span class="simple">simple #simple text text</span> STR; echo tagify($str);
Output for 5.2.3 - 5.6.28, 7.0.0 - 7.1.0
Warning: preg_replace(): Unknown modifier 'a' in /in/ef8Gd on line 10
Output for hhvm-3.10.0 - 3.12.0
Warning: Unknown modifier 'a': [/ (?!<a[^<>]*>[^\#]*) # Dont match if there is an opening <a> tag and any chars after it. \#([-_\w]+\b) # Match the hashtag. (?![^<]*<\/a>) # Ignore any anding </a> tag including any chars before it not in hashtag. /ix] in /in/ef8Gd on line 10
Output for 4.4.3 - 5.2.2
<br /> <b>Warning</b>: preg_replace() [<a href='function.preg-replace'>function.preg-replace</a>]: Unknown modifier 'a' in <b>/in/ef8Gd</b> on line <b>10</b><br />
Output for 4.3.11 - 4.4.2
<br /> <b>Warning</b>: preg_replace(): Unknown modifier 'a' in <b>/in/ef8Gd</b> on line <b>10</b><br />
Output for 4.3.0 - 4.3.10
<br /> <b>Warning</b>: Unknown modifier 'a' in <b>/in/ef8Gd</b> on line <b>10</b><br />