Hello everyone!
I'm trying to update a search script from one open source project, and I encountered a problem with fixing the following piece of code:
function formattext($whatfind, $text){
$pos = @strpos(strtoupper($text), strtoupper($whatfind));
$otstup = 200;
$result = '';
if ($pos !== false){
if ($pos < $otstup){
$result = substr($text, 0, $otstup * 2);
$result = eregi_replace($whatfind, '<span class="hilite">'.$whatfind.'</span>', $result);
} else {
$start = $pos-$otstup;
$result = '...'.substr($text, $pos-$otstup, $otstup * 2).'...';
$result = eregi_replace($whatfind, '<span class="hilite">'.$whatfind.'</span>', $result);
}
} else {
$result = substr($text, 0, $otstup * 2);
}
return $result;
}
On PHP 5.2.x everything works ok, however on PHP 5.3.x it shows following error:
Deprecated: Function eregi_replace() is deprecated in /home/hawkdesi/public_html/cms/search.php on line 113
I made following changes:
function formattext($whatfind, $text){
$pos = @strpos(strtoupper($text), strtoupper($whatfind));
$otstup = 200;
$result = '';
if ($pos !== false){
if ($pos < $otstup){
$result = substr($text, 0, $otstup * 2);
$result = preg_replace($whatfind, '/(<span class="hilite">)/i'.$whatfind.'/(</span>)/i', $result);
} else {
$start = $pos-$otstup;
$result = '...'.substr($text, $pos-$otstup, $otstup * 2).'...';
$result = preg_replace($whatfind, '/(<span class="hilite">)/i'.$whatfind.'/(</span>)/i', $result);
}
} else {
$result = substr($text, 0, $otstup * 2);
}
return $result;
}
however I'm getting some new errors again and am currently stuck.
Warning: preg_replace() [function.preg-replace]: Delimiter must not be alphanumeric or backslash in /home/test/public_html/cms/search.php on line 113
Warning: preg_replace() [function.preg-replace]: Unknown modifier '�' in /home/test/public_html/cms/search.php on line 113
Could anyone point me what I did wrong and how it should be done?
Thanks upfront!