| strtolower() and back again in php |
sarkye

msg:1298859 | 8:36 am on Feb 23, 2002 (gmt 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 :)
|
sugarkane

msg:1298860 | 5:23 pm on Feb 27, 2002 (gmt 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: [perl] preg_match_all(" http.*? ", $string, $upper_case_matches); $newstring=strtolower($string); preg_match_all(" http.*? ", $string, $lower_case_matches); preg_replace($lower_case_matches, $upper_case_matches, $newstring); [/perl] As I say, that's untested but might fire off a few ideas for you...
|
jatar_k

msg:1298861 | 7:35 pm on Feb 27, 2002 (gmt 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)) { strtolower($somestring); }
|
toadhall

msg:1298862 | 6:35 am on Feb 28, 2002 (gmt 0) | sarkye, 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?
|
sarkye

msg:1298863 | 7:44 am on Feb 28, 2002 (gmt 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
|
sarkye

msg:1298864 | 8:30 am on Mar 1, 2002 (gmt 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 :)
|
|
|