<?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.28, 5.4.0 - 5.4.24
- Parse error: syntax error, unexpected '%' in /in/Fg7k7 on line 26
Process exited with code 255.
preferences:
182.85 ms | 1387 KiB | 61 Q