user3599534
user3599534

Reputation: 404

Replace "&" (ampersand) with ";" (semicolon) in URL

I know what you will going to tell me, but for learning purpose I need to know how to change the & in URL with ; using PHP.

For Example:

I have a URL like

http://example.com/index.php?show=products&index=20&page=5

It will become

http://example.com/index.php?show=products;index=20;page=5

I saw this on ESPN Cricinfo like they use it for their stats, commentary, like this page uses it.

As I think, we use $_GET['...'] to get values from URL in PHP, but this method may use some other string functions.

I already said, if you know how then tell me how. It is only for learning purpose.

Upvotes: 3

Views: 1454

Answers (1)

VisioN
VisioN

Reputation: 145398

Set this option globally inside the php.ini file:

arg_separator.input = ";"

or locally for your current script execution with ini_set:

ini_set('arg_separator.input', ';');

From the docs:

arg_separator.input string

List of separator(s) used by PHP to parse input URLs into variables.

The option can receive a character set of possible separators, so if you need to make PHP parsing arguments both with semicolon and ampersand as a separator, set it equal to ;&.

Additionally arg_separator.output can be used to separate arguments in PHP generated URLs.

REF: http://www.php.net/manual/en/ini.core.php#ini.arg-separator.input

Upvotes: 8

Related Questions