user1581307
user1581307

Reputation: 15

preg_match_all extract from a text

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?

Upvotes: 0

Views: 85

Answers (1)

Casimir et Hippolyte
Casimir et Hippolyte

Reputation: 89557

You can try this with preg_match_all:

$pattern = '~(?:^\|.*\n)+~m';

Upvotes: 1

Related Questions