[Webdev] Using PHP variables line by line

adam beecher adam at iewebs.com
Thu Sep 14 10:27:08 IST 2000


> I've got a list of filenames in a variable.
> Just got them from a simple command.
> How do I parse it line by line?
> e.g. each file at a time?
>

If there's some kind of delimiter between them, use explode() to put them into
an array:

$filesAry = explode("\n", $filesStr);

If they're aleady in an array, use a looping structure to work with them:

for ($i=0; $i<count($filesAry); $i++) {
	do something to the array element;
}

If there's no delimiter, however, you'll need to use regular expressions, and
you'll need to be pretty sure of a pattern before you do that.

adam





More information about the Webdev mailing list