Alex Mathew
Alex Mathew

Reputation: 1554

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 Output

http:\/\/www.imdb.com\/title\/tt0796366\/

how can i change it to

http://www.imdb.com/title/tt0796366/

in PHP?

Upvotes: 0

Views: 321

Answers (4)

Jan Wy
Jan Wy

Reputation: 1569

$url = str_replace('\', '', $url);

Upvotes: 0

robjmills
robjmills

Reputation: 18598

$url = "http:\/\/www.imdb.com\/title\/tt0796366\/";
$url = str_replace("\/","/",$url);

example here http://ideone.com/J44Q6

Upvotes: 0

Spudley
Spudley

Reputation: 168685

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.

Upvotes: 0

Emil Vikström
Emil Vikström

Reputation: 91942

Use stripslashes:

$url = 'http:\/\/www.imdb.com\/title\/tt0796366\/';
$url = stripslashes($url);

Upvotes: 5

Related Questions