There is a text file:

<sq>fgafdsg</sq> <sq>fgafdsg</sq> <sq>fgafdsg</sq><sq> fgafdsg</sq> <sq>fgafdsg</sq> <sq>fgafdsg</sq> <sq>fgafdsg</sq> 

I need an array with all the texts between the <sq> tags

I do this:

 preg_match("#<sq>(.*)</sq>#si", $filecontent, $out); 

As a result, I get the output: $ out [0]:

  <sq>fgafdsg</sq> <sq>fgafdsg</sq> <sq>fgafdsg</sq><sq> fgafdsg</sq> <sq>fgafdsg</sq> <sq>fgafdsg</sq> <sq>fgafdsg</sq> 

$ out [1]:

  fgafdsg</sq> <sq>fgafdsg</sq> <sq>fgafdsg</sq><sq> fgafdsg</sq> <sq>fgafdsg</sq> <sq>fgafdsg</sq> <sq>fgafdsg 

Further the array is empty. What is the error, tell me, please. Previously, this was no problem. XML Parser do not offer.

1 answer 1

Add a modifier U , which diminishes regular greed. Like this:

 preg_match("#<sq>(.*)</sq>#Usi", $filecontent, $out); 

and in order to pull out all the texts - use

 preg_match_all("#<sq>(.*)</sq>#Usi", $filecontent, $out);