how do I grab a line from a field that has no boundaries and break in array?

-1

I have the code that takes a string from a field in the example below:

  

material plant part vazo light

This string has no boundaries and, as you can see, the string words I need to break have distinct characters running my code below the string looks like this:

  

planting material çavazolu z

The above string is just an example of my code problem, does anyone know how to solve this?

$text = $_POST["text"];
$plant = $_POST["combox"];

    mysql_query("Delete from flex_report.tab_mtm_ativos where planta = '$plant'");

    $count = strlen($text);

    for($i=0;$i < $count;$i++){
        if(strstr($text,"-")){
            $replace = str_replace("-","",$text);   
            $novaString = chunk_split($replace,12,".");
        }else{
            $novaString = chunk_split($text,9,".");
        }
    }

    //quebra array em string
    $bat = explode('.',$novaString);
    print_r($bat)."<br>";

I need the string to be split:

string = material planta peça luz chocolate

I want to break this string up like this in the example below:

string divide

  

0 = > material
  1 = > plant   2 = > piece   3 = > light   4 = > chocolate

This is what I need most with the code I made so it's okay

  

0 = > material
  1 = > plantape
  2 = > çaluzcho
  3 = > collate

    
asked by anonymous 19.04.2016 / 18:59

1 answer

1

In the string that you entered there is a delimiter, space.

Just "blast" the spaces.

$arr = explode(' ', $string);
    
19.04.2016 / 21:26