php > html - parse #
Im trying to parse a 'hash tag' (#) from php into ascii as part of an url. I've tried escaping the character in every possible way and also tried using ascii/ampersand codes, but whatever I try, it doesnt output an actual '#' in the url.
Example:
prin开发者_运维知识库t l('node/'.$node->nid.'/edit/2\#extra');
Ends up like:
http://local/node/212/edit/%5C%2523extra
Instead of:
http://local/node/212/edit/2#extra
I've tried searching the web using keywords like 'parse', 'echo', 'print' and 'escape' symbols in php, but to no avail. I'm sure one of you coding gods can answer this simple question ;)
I guess you are looking for the urlencode()
function
echo "http://local/node/212/edit/".urlencode("\#extra");
// Will output: http://local/node/212/edit/%5C%23extra
What is this l
function that you're using? It looks like its converting non-alphanumerics into HTTP entities to make them into valid URLs.
Just write print "node/{$node->nid}/edit/2#extra";
.
If you really need to use l
, and you're trying to append a page anchor, then do:
print l('node/'.$node->nid.'/edit/2') . '#' . l('extra');
精彩评论