开发者

How to encode # character in the url + php + Joomla

I am trying to fetch a variable address from my current URL using JRequest::getVar('address') method. But if the address value has a (#) character, the part after the # character is not retrieved.

I understand that URI is a combination of query + fragment and the part after a hash symbol is treated as a fragment. I have tried to use urlencode m开发者_如何学Goethod but it still doesn't solve the problem.

Can anyone please tell me how to solve the issue?


What is the problem with using urlencode? It should replace # with %23 and all should be well. You can try JRequest::getVar(str_replace('#', '%23', 'address')) which should do the trick. Can you post an example URL that doesn't get properly urlencoded?


I guess you will have to replace the hash-symbol on your own. For example:

str_replace($the_url, '#', '-');

I don't know, where exactly you have to do that, because I don't know how the Joomla!-Framework handles links and urls. But I am sure, that someone else can help here any further...


Encode the Hash in the URL with a %23 replacement

http://twitter.com/home?status=I+believe+in+%23love

"I believe in #love"


The part after # is never sent to Apache/PHP, and can therefore not be retrieved by a PHP script. What you need to do, is to url encode the ADDRESS parameter of the URL.

test.com/index.php?ADDRESS=<?= urlencode('101 Street #6 City') ?>

That code will generate the following url

test.com/index.php?ADDRESS=101+Street+%236+City

Now on this URL, you can retrieve address with JRequest::getVar('ADDRESS')


Check this Joomla doc out. You can retrieve what Joomla call the 'fragment' by doing:

$uri = 'http://fredbloggs:itsasecret@www.example.com:8080/path/to/Joomla/index.php?task=view&id=32#anchorthis';
$u =& JURI::getInstance( $uri );
echo 'Fragment is ' . $u->getFragment();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜