mevets Posted December 11, 2006 Share Posted December 11, 2006 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 More sharing options...
fert Posted December 11, 2006 Share Posted December 11, 2006 you mean[code]$text=explode("\n",$text);[/code] Link to comment https://forums.phpfreaks.com/topic/30183-parsing-loop/#findComment-138758 Share on other sites More sharing options...
linuxdream Posted December 12, 2006 Share Posted December 12, 2006 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 More sharing options...
mevets Posted December 12, 2006 Author Share Posted December 12, 2006 thanks, makes more sense Link to comment https://forums.phpfreaks.com/topic/30183-parsing-loop/#findComment-139571 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.