Hello. There is a variable:

$slova = "раз два три четыре пять"; 

I want to break it into separate words, but do not take into account spaces:

  $arr = explode("\n", $slova); foreach ($arr as $word) { $word = trim($word); echo $word."<br />"; } 

But in this case, spaces are taken into account. How to be?

    2 answers 2

     $slova = "раз два три четыре пять"; $data = preg_split('/\s+/', $slova); 

      You can use the regular schedule instead of explode:

       <?php $slova = "раз два три четыре пять"; $arr = preg_split("/( )+/", $slova); foreach ($arr as $word) { echo $word."<br />"; } 
      • 2
        And why trim in this version? $word can't contain blanks? - koks_rs
      • Yes, trim is not needed. quick copy-paste ^ _ ^ removed - myxaxa