You are here: Re: [PHP] problem encountered with stristr-based function « PHP « IT news, forums, messages
Re: [PHP] problem encountered with stristr-based function

Posted by "Richard Lynch" on 01/20/06 23:25

On Fri, January 20, 2006 8:44 am, George Pitcher wrote:
> function terms($term,$field){
> if(strlen($term)>0){
> if(!stristr($term, $field) === FALSE) {

This is quite contorted...
And you have the arguments swapped, which is the real problem.
if(stristr($field, $term)){

> $output = str_replace($term, "<b>".$term."</b>", $field);

The rest of this is just plain silly.
stristr ignores case in both args.

> } elseif(!stristr(strtolower($term), $field) === FALSE) {
> $output = str_replace(strtolower($term),
> "<b>".strtolower($term)."</b>", $field);
> } elseif(!stristr(strtoupper($term), $field) === FALSE) {
> $output = str_replace(strtoupper($term),
> "<b>".strtoupper($term)."</b>", $field);
> } elseif(!stristr(ucfirst($term), $field) === FALSE) {
> $output = str_replace(ucfirst($term),
> "<b>".ucfirst($term)."</b>",
> $field);
> }
> } else {
> $output = $field;
> }
> return $output;
> }
> I'm not comfortable enough with regex etc, so tried it my way, but no
> joy.
>
> For info, I am trying to highlight search terms in results.
>
> Any suggestions?

http://php.net/stristr

--
Like Music?
http://l-i-e.com/artists.htm

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация