Jump to content

Parsing loop


mevets

Recommended Posts

Hey, I am wondering how I can perform a loop that parse a string.

I am hoping I can create a loop that loops for each item in a strinig(linebreaks separate each item). Then on each iteration I'd be able to use the loop's field (on the first iteration id get the first line, on the 2nd iteration id get the 2nd line, etc).

I tried reading up on examples that parsed XML, but they got into the foreach loop that i was unfamiliar with. Any help is welcome.
Link to comment
https://forums.phpfreaks.com/topic/30183-parsing-loop/
Share on other sites

Yea, explode then foreach if it's a small loop (for, is more efficient than a foreach for arrays with a lot of data).
[code]
<?php
$data = "something|nothing|again|and again";
$adata = explode('|', $data);
foreach($adata as $item){
    echo $item . "<br />";
}
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/30183-parsing-loop/#findComment-139371
Share on other sites

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.