consider my website's URL is https://www.sitename.com/compare/product/product-name-s10-compare-102883.html?id=102903-102904-102905
I want to detect the 102903 and 102904 and 102905 separately.
Using $id1 = $_GET[ 'pid' ];
will give the 102903-102904-102905
as output. But I want $id1
,$id2
,$id3
separately.
This function is to detect product ID from URL and show the comparison data in the page.
Asked
Active
Viewed 39 times
-1

Shijil
- 9
- 6
-
_"Using $id1 = $_GET[ 'pid' ]; will give the 102903-102904-102905"_ No it won't. Anyway, look into PHP's [`explode()`](https://www.php.net/manual/en/function.explode.php) function – j08691 Aug 01 '20 at 17:10
-
@j08691, Thank You explode function seems to be working fine. – Shijil Aug 01 '20 at 17:17
-
Does this answer your question? [explode single variable in php](https://stackoverflow.com/questions/26055215/explode-single-variable-in-php) – sanoj lawrence Aug 01 '20 at 17:18
1 Answers
2
When you look at $_GET['id']
you get the entire string after the =
sign, until the next variable. To split the string into three variables, use the split()
function to create an array with separating by a string. The code for that would become something like this:
$id = split('-', $_GET['id']);
$id1 = $id[0];
$id2 = $id[1];
$id3 = $id[2];

J0R1AN
- 583
- 7
- 10
-
Thank You, both the explode and split functions seems to be working fine. – Shijil Aug 01 '20 at 17:16
-
Great, here on Stack Overflow you can mark an answer as solved, that way people will know what solved the problem and that they don't need to answer themselves. You can do this by clicking the checkmark left to the answer :) – J0R1AN Aug 01 '20 at 17:18