|strtolower() and back again|
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 :)
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...
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))
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?
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
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 :)