homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

strtolower() and back again
in php

 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 :)



 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:

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)

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)

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)

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)

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 :)

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved