Brent Gorridon
Brent Gorridon

Reputation: 11

Remove symbols from link '($_SERVER['REQUEST_URI'])).'

Currently using this code:

str_replace(".php","",basename($_SERVER['REQUEST_URI']))

and it outputs like this:

Rusko%20-%20Skanker.mp3&sort=1

i need it to display so: Rusko - Skanker

Upvotes: 1

Views: 345

Answers (2)

Colin M
Colin M

Reputation: 13328

Say you have the following URL:

script.php?file=Rusko%20-%20Sanker.mp3&sort=1

Then, to get the result you are looking for, you would want:

echo htmlentities( urldecode( str_replace( '.mp3', '', $_GET['file'] ) ), ENT_QUOTES );

The other answers aren't quite complete because they will include the entire URL in the output. You seem to be looking for just one query string parameter.

Note: htmlentities() is VERY important in this case to protect your website and users. Printing any user submitted data on a page without properly sanitizing it first allows for code injection.

Upvotes: 1

Mihai Iorga
Mihai Iorga

Reputation: 39704

you can use urldecode():

urldecode($_SERVER['REQUEST_URI']);

Upvotes: 3

Related Questions