Jump to content

[SOLVED] How to count the number of commas, and then cut off after 2nd case?


LiliVG

Recommended Posts

This is how far I've gotten. So far, $page_code would print something like "read.php?1,2,2"

 

$page_url = $_SERVER['HTTP_REFERER'];

$parse = parse_url($page_url);

$path = $parse['path'];

$query = $parse['query'];

$page_code = $path.$query;

 

 

I want to cut off anything including and after the second comma, how would I do that so I end up with $page_code == "read.php?1,2" ?

you could also use:

$url = 'http://www.somesite.com/read.php?1,2,2,4,5';
$url = explode( ',' , $url);
$final = $url['0'] . $url['1'];
echo $final;

 

This looks interesting, I think I'll give that a shot! :)

 

Very close! It does *almost* what I need. I cuts off everything including and after the second comma, BUT, it removes the first comma, which I need...

Ok, I got it, I changed

 

$final = $url['0'] . $url['1'];

 

to

 

$final = $url['0'] .','. $url['1'];

 

and that works. Explode() seems to use the character as a divider, and removes it from the results, at least in the first case with 0 it does.

 

Anyways, it works, thanks! :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.