Forum Moderators: coopster

Message Too Old, No Replies

Capital letters in PHP

How to replace letters in query?

         

alste123

6:29 pm on May 5, 2006 (gmt 0)

10+ Year Member



Hi,
I have a script which allows the user to search a certain table. On the results page, I want to bolden or change the color of the text matching the query. However, if the user searches for 'blogs' and, in the table, the matching row contains 'Blogs', the word Blogs on the results page won't be boldened.

Is there a way to replace a string with another without case sensivity?

I am using str_replace, and cannot use str_ireplace because I do not have PHP 5 CVS.

Any suggestions are welcome.

Thanks in advance.

eelixduppy

6:46 pm on May 5, 2006 (gmt 0)



Hello...

I woiuld try something like this:


$query = strtolower($query);
$result_from_table = strtolower($result_from_table);
$pos = strpos($result_from_table, $query);
if($pos) {
echo "Found $query! at $pos<br>";
}
else {
echo "not found!<br>";
}

hope this helps!

eelix

coopster

3:00 pm on May 8, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You could also use regular expressions [php.net].