0

I can print a url with the following:

<?php print $base_url . $node_url ?>

What is the standard PHP way of converting special characters?

So instead of: http://time.com/3525666/ebola-psychology-fear-symptoms/

I need http%3A%2F%2Ftime.com%2F3525666%2Febola-psychology-fear-symptoms%2F

Evanss
  • 23,390
  • 94
  • 282
  • 505
  • 1
    have you looked at [urlencode](http://php.net/manual/en/function.urlencode.php)? – vch Oct 22 '14 at 19:35

3 Answers3

1

You would use urlencode for that sort of escaping.

Other escaping functions exist for other purposes, like htmlspecialchars for making text output safely for HTML display.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
1

use his function in php , it is built in function to encode in url format

  urlencode(); 
A.B
  • 20,110
  • 3
  • 37
  • 71
0

Just to add, htmlspecialchars, as mentioned above in the comment can take care of few html entities, not all of them.

Use htmlentities() instead:

$query_string = 'foo=' .urlencode($foo) . '&bar=' . urlencode($bar);echo '';