rawurlencode() problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ncic_1
Forum Newbie
Posts: 6
Joined: Wed Mar 03, 2004 9:35 am
Location: Crawfordville, Fl

rawurlencode() problem

Post by ncic_1 »

:D Hey,

I am trying to change the blank spaces in my url's to %20 with the rawurlencode function. When I hover over a hyperlink the status bar will show the correct hyperlink like http://test/test%20page, but when I click on the hyperlink I am prompted to open the page with a program because windows doesn't seem to recognize the extension. I will then choose Internet Explorer to open the page and I get an error explaining that the page cannot be opened and the hyperlink that I described earlier will be shown as http://test/test%2520page. There will be a 25 thrown in between the % sign and the # 20. Thanks for your help.
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

There is no extension to page. Try dis:

Code: Select all

$urlo="http://www.test.com/test page.html";
$newurl=rawurlencode("$urlo");
echo "$newurl";
//should output http://www.test.com/test%20page.html
User avatar
ncic_1
Forum Newbie
Posts: 6
Joined: Wed Mar 03, 2004 9:35 am
Location: Crawfordville, Fl

Post by ncic_1 »

Sorry about that, bad example. What I am really trying to navigate to is a folder that exist somewhere in my site directory. Like test folder.

so my hyperlink would look like http://test/test folder normally

and I want http://test/test%20folder

but I keep getting http://test/test%2520folder.

Thanks again for your help
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

I was wrong in any case. Worth a try... :)
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Of course the obvious answer is to not use spaces in your file or folder names because it causes more hassles than it's worth (underscores work just as well).

For the problem in hand though, it looks like the url is being encoded twice - %25 is the urlencoding for the % symbol - check the output of:

Code: Select all

<?php

$url = 'test folder';
echo rawurlencode(rawurlencode($url));

?>
Mac
User avatar
ncic_1
Forum Newbie
Posts: 6
Joined: Wed Mar 03, 2004 9:35 am
Location: Crawfordville, Fl

Post by ncic_1 »

Thanks I'll give it a go when I get some free time.
Post Reply