PDA

View Full Version : Seperating by commas (,)


TrainReq
12-09-2006, 05:47 AM
I have some stuff going as

www.site.com/file.php?variable=222, 333, 444, 555


and how would i get it to on the other site, they will seperate as
<a href=http://samplesite.com/222> <br> <a href=http://samplesite.com/3333> ,

If i do regular GET 222, i'll end up coming out with <a href=http://samplesite.com/222, 333, 444, 555> and i dont want that..

So i would like it to seperate at the commas and write as that.

mlseim
12-09-2006, 08:05 AM
Try this:


<?php

// read the variable from your link (variable=111,222,333,444)
$variable=$_REQUEST['variable'];

// separate the items between commas and put into an array
$pieces = explode(",", $variable);

// count how many you have and loop through them
$count_array=count($pieces);
for ($i=0;$i<$count_array;$i++) {
echo "http://www.mysite.com/$pieces[$i] <br> \n";
}
?>