How to Format this type of URL in PHP?
Hey Friends,
I am using the following API for getting details of IMDB,http://www.deanclatworthy.com/imdb/?q=Star+Trek while i using following API i am getting URL as following Outputhttp:\/\/www.imdb.com\/t开发者_开发问答itle\/tt0796366\/
how can i change it to
http://www.imdb.com/title/tt0796366/
in PHP?
Use stripslashes:
$url = 'http:\/\/www.imdb.com\/title\/tt0796366\/';
$url = stripslashes($url);
The URL has been escaped - that is, it has had a back-slash character added in front of certain other characters which could cause issues, eg if they were put into a SQL string.
PHP has a command stripslashes()
to remove these escape characters.
However, the feature of PHP adding the slashes automatically is old and is now deprecated. If possible, you should check your PHP.ini and turn off the magic_quotes
option. That way you won't get the slashes added to your input any more, so you won't have to remove them.
Note that if you are writing data to a database, you will need to escape it before putting it in your SQL string. But you should use something like mysql_real_escape_string()
instead of the slashes added by magic_quotes.
$url = "http:\/\/www.imdb.com\/title\/tt0796366\/";
$url = str_replace("\/","/",$url);
example here http://ideone.com/J44Q6
$url = str_replace('\', '', $url);
精彩评论