search result highlighting in php

searching in an article for a particular group of words and if found, highlighting the search criteria in the result is really cool. we have seen this in google and many other search engines crawling in the internet. doing texthighlighting in php is fun and easy. i going to describe a little about that.

suppose we are going to search for ‘fineagain’. suppose we have defined a style named ’search’ in css which is different from the style used in the article. we will be displaying search criteria in the result in this style.

let us define some variables according to our need.

$body = is the whole article in which we have found our criteria.

$criteria =’fineagain’;

$startingTag = “<span class=’search’>”;

$endingTag = “</span>”;

$highlightedText = $startingTag . $criteria . $endingTag;

the variable $criteria and $hightedText are same but with different style. we whenever we find $criteria, we replace it with $highlightedText. this will show the search criteria differently in the result.

to replace the $criteria with $highlightedText, we use php library function ‘eregi_replace’.

the defination of the function is:

string eregi_replace(string pattern, string replacement, string textBody);

here pattern is the string we are searching for.

replacement is the string we will use in place of pattern.

textBody is the whole article in which we found our search criteria.

so we will call the function is the following way:

$body = eregi_replace($criteria,$highlightedText,$body);

thats all. now $body contains the same article but the search criteria is highlighted.

this article shows only a single word criterion but it can be extended to multiple word criteria. we can also change highlighting dynamically with utilization of a little prudence.

smarty — i rEAlly WanTed

i am not that expert in php. i am still learning. lately i was doing php programming for an online it magazine going to be public soon. it was not a very big work though. i found an urgence for something that can seperate the presentation layer and logic layer. that is, i’ll be able to do logic work at will without  bothering about the presentation layer. in same way, logic layer will not bother me when i am doing designing  that is working on presentation layer.  i a crude sense mix-up of these two layers is not that big a problem when i am working on smaller project. but if project goes bigger , it invites trouble if both the layers speghettied. so i was longing for some thing to help me out. at some stage , i thought to develop some solution.  smarty  saved my lots of valuablehours. smarty is really what i was looking. it is so important a tool but so easy to use. thanks to the developers of smarty. thank u so much.

storing and retriving bangla text in mysql database using php

lately i was doing e-magazine development work. there i had to do bangla text storing and retrival work in mysql database. at first place it was an easy go. but i succeeded at last. thank u so much hasin vai(hasin hyder,somewherein.net).

all i have to do is to add the following two lines after the call of mysql_select _db() function:

mysql_query(’SET CHARACTER SET utf8′);
mysql_query(”SET SESSION collation_connection =’utf8_general_ci’”);

this was really fun.