$alltext
variable contents this code inside:
<li>sometext</开发者_如何学Cli><li>sometext</li>
<li>sometext</li><li>sometext</li>
How do I get each <li>...</li>
like an item of an array?
If each element is separated by a "new line", you could try:
$array = explode("\n",$alltext);
If they aren't, then:
$array = explode("</li>");
foreach($array as $k=>$v){
$array[$k] = $v."</li>";
}
$array = explode("\n", $alltext);
It seems like you should have a better approach, though.
If text is separated by new line, you could do this:
$arr = explode("\r\n", $alltext);
foreach($arr as $val){
echo $val;
}
You would use \n
if not under Windows.
Same answer as from @Sarfraz and @Dave Kiss, but crossplatform:
$listItems = explode(PHP_EOL, $alltext);
However, I agree with Dave Kiss when he says you should have a better approach (in software design).
use explode function, use '\r\n' (linebreak) as a splitter
精彩评论