dimanche 28 juin 2015

Exploding txt file PHP

I am having a problem exploding a txt file in PHP. Here is an example of what I want to do:

Product N°3456788765
price: 0.09
name: carambar


Product N°3456789
price: 9
name: bread

So basically, I would like to have an array like:

array
    [0] => 
           [0] => Product N°3456788765
           [1] => price: 0.09
           [2] => name: carambar
    [] => 
           [0] => Product N°3456789
           [1] => price: 9
           [2] => name: bread

In the others questions, they used the explode function. Unfortunately, I don't know what to say to the function because delimiters are blank lines here...

I tried to make some research because when I go with a strlen() on a blank line, it shows 2 caracters. So after using ord() function, I saw that these two caracters were 13 and 10 in Ascii mode, but if I try a

$string = chr(13) . chr(10);
strcmp($string,$blankline); 

It just doesn't work. I would have loved to use this $string in my explode delimiter...

Thank you all for you advices, first post here after many years finding answers :)

Aucun commentaire:

Enregistrer un commentaire