note 88863 deleted from function.eregi-replace by yannick
| From: | yannick@php.net | Date: | Wed, 11 Feb 2009 15:17:55 +0000 |
| Subject: | note 88863 deleted from function.eregi-replace by yannick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-150488@lists.php.net to get a copy of this message | ||
Note Submitter: ekremekrem at hotmail dot com
Reason: non-english
----
Ben birazcık daha geliÅtirdim :)
<?php
function hilite_text($subject, $word, $style = ' class="hilite"')
{
$word = preg_replace("(\s+)", " ", $word);
$words = preg_split('(\s)', $word);
for ($j = 0; $j < count($words); $j++) {
$regex_chars = '\.+?(){}[]^$';
for ($i = 0; $i < strlen($regex_chars); $i++) {
$char = substr($regex_chars, $i, 1);
$words[$j] = str_replace($char, '\\'.$char, $words[$j]);
}
$history = "<span{$style}>{$words[$j]}</span>";
$words[$j] = '(.*)('.$words[$j].')(.*)';
if (!eregi($history, $subject)) {
$subject = eregi_replace($words[$j], "\\1<span{$style}>\\2</span>\\3",
$subject);
}
}
return $subject;
}
?>