3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $message = 'choukai kai hey this matches too 423-2123'; $search = array('surfing', 'joke and stuff', 'smile and etc', '3-2', 'choukai kai', 'choukai'); // Massage the message $message = preg_replace( '/(' . implode('|', array_map('preg_quote', $search)) . ')/i', '%%$1%%', $message ); $replacements = array( // here all replaces | each in a new line - watch the syntax // all html possible, but no single quotation mark! '<a href="http://en.wikipedia.org/wiki/Surfing" style="color:darkred;font-weight:bold;">surfing</a>', '<a href="http://en.wikipedia.org/wiki/Joke" style="color:darkred;font-weight:bold;">joke</a>', '<a href="http://en.wikipedia.org/wiki/Smiling" style="color:darkred;font-weight:bold;">Smile</a>', '<a class="screenshot" rel="3-2_Map.jpg">3-2</a>', '<a href="http://en.wikipedia.org/wiki/Joke" style="color:darkred;font-weight:bold;">Choukai Kai</a>', '<a href="http://en.wikipedia.org/wiki/Smiling" style="color:darkred;font-weight:bold;">Choukai</a>' ); $message = str_replace( array_map(function($s) { return '%%' . $s . '%%'; }, $search), $replacements, $message ); var_dump($message);
Output for 5.3.0 - 7.1.0
string(173) "<a href="http://en.wikipedia.org/wiki/Joke" style="color:darkred;font-weight:bold;">Choukai Kai</a> hey this matches too 42<a class="screenshot" rel="3-2_Map.jpg">3-2</a>123"
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in /in/poUuo on line 26
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION, expecting ')' in /in/poUuo on line 26
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/poUuo on line 26
Process exited with code 255.