Welcome to WebmasterWorld Guest from 107.20.5.156

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

strtolower() and back again

in php

     

sarkye

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

10+ Year Member



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

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

WebmasterWorld Senior Member 10+ Year Member



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

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

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



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

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

10+ Year Member



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

7:44 am on Feb 28, 2002 (gmt 0)

10+ Year Member



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

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

10+ Year Member



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