1

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:

print 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 ;)

0

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

Comments

0

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');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.