Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

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.

like image 451
user3599534 Avatar asked Dec 03 '25 01:12

user3599534


1 Answers

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

like image 178
VisioN Avatar answered Dec 05 '25 14:12

VisioN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!