Split new line after certain character

时间:2018-02-03 10:24:53

标签: php

Hello i try to make this

I have variable with this

  $var = 'text;text2;text3';

I want after ; to split on new line with foreach i want to make something like this

$var = 'text1;text2;text3';
// here is splitter or anything i dont know

foreach($var as $i) {
echo $i;
}

Output will be

 text1
 text2
 text3

1 个答案:

答案 0 :(得分:0)

You can use explode() to do this:

$var = 'text;text2;text3';
$cmds = explode(';', $var) ;
foreach ($cmds as $cmd) {
    // echo $cmd ; // do something with $cmd
    $rcon->sendCommand($cmd) ;
}