Page 1 of 1

rawurlencode() problem

Posted: Mon Mar 08, 2004 10:23 am
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.

Posted: Mon Mar 08, 2004 10:56 am
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

Posted: Mon Mar 08, 2004 11:29 am
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

Posted: Mon Mar 08, 2004 11:56 pm
by Steveo31
I was wrong in any case. Worth a try... :)

Posted: Tue Mar 09, 2004 3:24 am
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

Posted: Tue Mar 09, 2004 6:24 am
by ncic_1
Thanks I'll give it a go when I get some free time.