Drupal – Escape the Hex Characters in drupal_goto()

In Drupal, you can redirect to a specific URL using the drupal_goto() method. For example, if you want to go to a node with nid = 100, the following code will do.

drupal_goto("node/100");

 

But this does not work if the URL contains query strings since some special characters will be converted to Hex. say if you put “node/100?blog=eureka&name=ykyuen” in drupal_goto(), you will get the following resulted string which leads to a 404 page not found.

http://<drupal-domain>/node%3Fblog%3deureka%26name%3dykyuen

 

The work around is construct the query string using http_build_query().

$q = array();
$q['blog'] = "eureka";
$q['name'] = "ykyuen";
$querystring = http_build_query($q);
drupal_goto("node/100", $querystring);

 

Done =)

Reference:

3 thoughts on “Drupal – Escape the Hex Characters in drupal_goto()”

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.