I'm trying to use preg_match_all to extract an array from a text array format:

explanation: i've this kind of texte

mynicetext
text with other elements
|my first Column            |my second column   |
|my data in first column    |data 2             |    
|my data in first column    |data 3             |       
....   
other text
text with other elements
|my first Column            |my second column   | My last column |
|my data in first column    |data 2             |data 2          |     
|my data in first column    |data 3             |data 2          |
....

I want to extract a full array like this:

|my first Column            |my second column   |
|my data in first column    |data 2             |    
|my data in first column    |data 3             | 

I've tried to use this to ~(\s*\n)\|(.*)\|(\s*\n)~ to extract but i cut lines caused by the carriage return.

|my first Column            |my second column   |

then

|my data in first column    |data 2             | 

...

Any idea?

有帮助吗?

解决方案

You can try this with preg_match_all:

$pattern = '~(?:^\|.*\n)+~m';
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top