View Full Version : List break-down

05-17-2007, 06:53 PM
I was wondering if there was a function that could identify components of a comma-seperated list (or any character for seperation--doesn't have to be a comma) and make an array out of them?

So it would basically change "12,15,1,4,7,322,41" and convert it to "array[0] = 12; array[1] = 15; array[2] = 1..."

I looked through PHP.net, but I don't know the proper name for the technique (I thought it might be parsing, but evidently not?) so it wasn't much help.


05-17-2007, 06:59 PM
$new_array = explode("character",$string);

05-17-2007, 07:03 PM
$new_array = explode("character",$string);
Where "character" would, in this case, be ','.

05-17-2007, 07:09 PM
and then after you do what you want with the "array" you can convert it back to a string by

$tring = implode(delimiter, $new_array);

usually a good re-delimiter is a blank space " " or a comma - space ", "

05-23-2007, 10:09 PM
Thanks a lot. Also, I was looking at the explode() function and was thinking of making a sort of webspider. I was wondering if there was a way to capture all text between certain HTML tags (for instance, I'd want all data between <td id="data"> and </td>, or something to that effect).

Also, for that same project, can fopen() and fread() successfully open pages that are the result of a query string? For instance, could I read the HTML output by the following URL just as if it were an actual hand-typed HTML file?: http://sample.com/index.php?step=die_in_fire

I appreciate your help.