Forum Moderators: coopster

Message Too Old, No Replies

Strange happenings with str_replace()

str_replace function doesnt seem to work for long strings such as URLs

         

crookyboy

2:32 pm on Sep 14, 2003 (gmt 0)

10+ Year Member



Hey,

I am using the following code:

// if "site" = [webmasterworld.com...] ....

$site = strtolower($_GET['site']);
$delete = array("http://", "ftp://","www.");
$show = str_replace($delete, "", $site);

// $show will hold the value "webmasterworld.com"

this works! What doesn't work is if I put "site" as "http://www.webmasterworld.com/forum/89/images/whatever".

What is going wrong?

dmorison

2:39 pm on Sep 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looks fine - what is $show holding when it goes wrong?

crookyboy

2:42 pm on Sep 14, 2003 (gmt 0)

10+ Year Member



it holds "http://www.webmasterworld.com/forum/89/images/whatever"

as though it hasnt performed the str_replace at all

dmorison

2:57 pm on Sep 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Odd! Just tried your exact code - works fine in 4.1.1.

crookyboy

3:14 pm on Sep 14, 2003 (gmt 0)

10+ Year Member



strange, ill keep working on it, see what happens...

crookyboy

3:19 pm on Sep 14, 2003 (gmt 0)

10+ Year Member



I also have another problem which I havent a clue how to fix.

When a "URL" is passed to the script in this way:

?url=http://www.google.com

it works fine, but if the URL has variables in it like:

?url=http://www.google.com/?q=Webmaster+World&LANG=UK

it chops of the &LANG part because it is concidered as another variable. How can I take only the variable "url" as a complete string from "http://" to "UK"

Cheers

James

dmorison

3:29 pm on Sep 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you aware of parse_url() [uk.php.net]

crookyboy

3:36 pm on Sep 14, 2003 (gmt 0)

10+ Year Member



Thats the one, was trying to remember it - thought it was url_encode for some reason