I just spent the whole night writing this little script for my search engine. Now i want to improve it.
Any ideas?
<?php
echo "KEYWORDS : ". $searchstring = "the and";
$sentence = "Skype Home is unavailable at the moment. Check back later to see your news and alerts. It's easy to start a conversation on Skype: Choose a contact and start talking Call a phone or mobile from the dial pad, or send an SMS.";
echo "<br><br><b>ORIGINAL STRING</b><br><br>$sentence";
$kt=split(' ',$searchstring); //Breaking the string to array of words
$num=1;
while(list($key,$val)=each($kt)){
// do not load sentence from session on first run!
if($num<=1){
} else {
$sentence = $_SESSION['NewSentence'];
}
if($val<>" " and strlen($val) > 0){
// make keyword bold and send entire sentence to session
$_SESSION['NewSentence'] = eregi_replace ("$val", "<b>$val</b>", $sentence);
// output sentence with added keyword
echo "<br><br>$num bolding: <b style='color:green;'>$val</b> <br><br> ".$_SESSION['NewSentence'];
$num++;
}
}
// make all bold keywords to red`
echo '<br><br><b>FINAL STRING</b><br><br>';
echo $_SESSION['NewSentence'] = eregi_replace ("<b>", "<b style='color:red'>", $_SESSION['NewSentence']);
//destroy session
unset($_SESSION['NewSentence']);
session_unregister($_SESSION['NewSentence']);?>