Pound sign (#) in link is being replaced by %23 when using link l($title, $path...).... How do I keep it as #?
ajwwong - August 30, 2006 - 06:39
Hey gang, :-)
Ok, so I'm trying to follow the Drupal way and use the link l() wrapper to do my links. :-)
Basically, I want to set up a link to point to this particular anchored spot on the web page:
http://www.ithou.org/user/2/edit/#edit-picture_deleteHowever, when I set this up as my link:
<?php
l('Update your Picture', "user/$uid/edit/#edit-picture_delete",
array('title' => t('Update Picture.')), NULL, NULL, FALSE, TRUE);
?>I get sent to this html address:
http://www.ithou.org/user/2/edit/%23edit-picture_deleteNote the way in which the pound sign # got replaced by %23.
I've looked over some of the APIs... and it looks like drupal_urlencode is doing some kind of substitution?
Anyhow, how do I make it stop substituting in the %23?
Thanks!
Albert
www.ithou.org

Surely that is correct URL
Surely that is correct URL encoding? And they are identical URLs.
PS It isnt a pound sign, it is a hash :-)
keep your #: use the fifth parameter to l()
Hi,
if you look at the code to the function l() in includes/common.inc you will find a 5th parameter which is especially for your problem. So your code should read something like:
<?phpl('Update your Picture', "user/$uid/edit/",
array('title' => t('Update Picture.')), NULL, "edit-picture_delete", FALSE, TRUE);
?>
regards
Stefan
Awesome!!! Thanks a million, stefan!
That looks like it's gonna be perfect! Thanks so much :-)
Albert
Esalen Alumni Group
Thanks
Thanks for this. I've asked about this several times but not had answers.
M
problematic drupal_urlencode
I have Drupal 4.7.4 installed on a Fedora Core 4 machine with Apache server (with all of the latest updates...). As I've noticed some issues with links containing %23 or %2523 (non-working link to a new comment - for anonymous user only, when go indirectly through login screen - in a comment module, link to unsubscribe in a notify module), I've edited a bit the drupal_urlencode($text) function - instead of replacements (line 1322 of common.inc) array('/', '%2526', '%2523') I am using array('/', '&', '#') now, and it seems my problems have disappeared... Everything seems to work just fine, even if not tested deeply until now.
1. Is it OK like that, or which (negative?) consequences can I expect?
2. If it is OK, why it is not like that in Drupal by default?
i had the same problem - i hope yout fix works
hello
i had the same problem - i hope your fix works :)
are we the only ones with this problem? its core ... normally it has to be a big problem for a lot of sites ...
greetings momper
i had the same problem - i hope yout fix works
hello
original:
function drupal_urlencode($text) {
if (variable_get('clean_url', '0')) {
return str_replace(array('%2F', '%26', '%23'),
array('/', '%2526', '%2523'),
urlencode($text));
}
else {
return str_replace('%2F', '/', urlencode($text));
}
}
modified fix:
function drupal_urlencode($text) {
if (variable_get('clean_url', '0')) {
return str_replace(array('%2F', '%26', '%2523'),
array('/', '&', '#'),
urlencode($text));
}
else {
return str_replace('%2F', '/', urlencode($text));
}
}
i had the same problem - i hope the fix works :)
are we the only ones with this problem? its core ... normally it has to be a big problem for a lot of sites ...
greetings momper
Try this
function drupal_urlencode($text) {
if (variable_get('clean_url', '0')) {
return urldecode(str_replace(array('%2F', '%26', '%23'),
array('/', '%2526', '%2523'),
urlencode($text)));
}
else {
return urldecode(str_replace('%2F', '/', urlencode($text)));
}
}
Thanks guys. This last one
Thanks guys.
This last one worked for me but since I had more suspect chracters ('?', '=') I had to add them. My code ended up looking like:
function drupal_urlencode($text) {if (variable_get('clean_url', '0')) {
return str_replace(array('%2F', '%3F', '%3D', '%26', '%2523'),
array('/', '?', '=', '&', '#'),
urlencode($text));
}
else {
return str_replace('%2F', '/', urlencode($text));
}
}
I'm not able to get it to
I'm not able to get it to work with any of those functions for Drupal 6. Anyone out there had any success with this in Drupal 6? Just want to replace my # (hash) correctly in php link (keeps coming up with %23 or %2523). Is the url() function better at this than the l() function prehaps? See more details at www.drupal.org/node/255558 .
Thanks,
Andrew G