Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

strtolower() and back again

in php

8:36 am on Feb 23, 2002 (gmt 0)

Junior Member

10+ Year Member

joined:Oct 19, 2001
votes: 0

I have text stored in a mySQL database and I output it using strtolower($foo) to take out all caps (obviously).

now, if there happens to be a url in the text, my page automatically creates a link, but if the original link contains some uppercase characters I'm in a bit of a pickle, aren't I?

Does anyone happen to have a magic line or two, to make strtolower() ignore URLs?

Thanks in advance :)

5:23 pm on Feb 27, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 6, 2000
votes: 0

This is a bit of a kludge (and untested) but you could find all URLs with a regular expression, use strtolower() and then reinsert the original URLs with another couple of regular expressions, eg:

preg_match_all(" http.*? ", $string, $upper_case_matches);
preg_match_all(" http.*? ", $string, $lower_case_matches);
preg_replace($lower_case_matches, $upper_case_matches, $newstring);

As I say, that's untested but might fire off a few ideas for you...

7:35 pm on Feb 27, 2002 (gmt 0)


WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
votes: 0

If all of your urls have the same format with http I would do (sorry my regex is bad so I didn't put it in)

if (!preg_match(string pattern, string subject))

6:35 am on Feb 28, 2002 (gmt 0)

Preferred Member

10+ Year Member

joined:May 9, 2001
votes: 0

Perhaps I've been up island too long (mountain air and fresh halibut) but I can't see the problem. URLs are case insensitive.
So, what am I missing?
Tartar sauce?
7:44 am on Feb 28, 2002 (gmt 0)

Junior Member

10+ Year Member

joined:Oct 19, 2001
votes: 0

thanks sugarkane! i should be able to get around to playing with that over the next couple of days and i'll let you know how i get on :)

jatar_k, unfortunately the urls will not all have the same format, they'll likely be all over the place!

and toadhall, welcome back :) and correct me if i'm wrong but... i think if the url contains a filename at the end it will matter very much that the correct case is used.

thanks again everyone

8:30 am on Mar 1, 2002 (gmt 0)

Junior Member

10+ Year Member

joined:Oct 19, 2001
votes: 0

I've tried it... as is and bent and twisted a bit but I can't get it to do what I wanted. During the time I spent playing with your four lines sugarkane I was sitting here with my PHP bible to help me understand what each part was doing and I think I learned enough to say only this, I don't understand why it doesn't work!

I'm going to keep trying but if anyone happens to know the answer I'd sure appreciate it :)