<?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 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.6 - 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
- 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.1.6, 5.2.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.3.11, 4.4.0 - 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.
preferences:
282.54 ms | 401 KiB | 355 Q