- microtime: documentation ( source)
- preg_match_all: documentation ( source)
- str_replace: documentation ( source)
- preg_quote: documentation ( source)
<?php
class Chat {
public static function linkifyMessage($message) {
$threadUrl = "http://forum.freewar.de/viewtopic.php?";
$threadPattern = "@".preg_quote($threadUrl)."f=(\d+)&t=(\d+)((&p=(\d+)(#p(\d+))?)|&view=unread(#unread)?)?@i";
preg_match_all($threadPattern, $message, $matches, PREG_SET_ORDER);
foreach($matches as $match) {
$message = str_replace($match[0], "<a href='{$match[0]}' target='_blank'>{$match[0]}</a>", $message);
}
return $message;
}
}
$start = microtime(1);
for($i = 0; $i < 10; $i++) {
Chat::linkifyMessage('Guckt mal das Update: http://forum.freewar.de/viewtopic.php?f=8&t=52663');
}
echo $i;
echo "\n";
echo (microtime(1) - $start) / $i;