I have a complex string that represents database tables. And I need to extract that database tables separately to process them.
Here’s the string example:
First table
| | {{Категория}} | | {{Стоимость курсов}} | {{Стоимость учебного набора}} |
| 1 | Взрослый | 1 уровень = 50ч | 1~500 лей | 15 евро |
| 2 | Студент, Мастерант, Докторант | 1 уровень = 50ч | 1~000 лей | 15 евро |
| 3 | Ученик | 1 уровень = 50ч | 1~000 лей | 15 евро |
| 4 | Пенсионер | 1 уровень = 50ч | 1~000 лей | 15 евро |
text text text text text text
Second table:
| | {{Вид курсов}} | | {{Стоимость курсов}}| {{Стоимость учебного набора}} |
| 1 | dfgdfgdfg | 1 модуль | 500 лей | 0 |
|^|^| 2 модуля | 900 лей | 0 |
|^|^| 4 модуля | 1~500 лей | 0 |
| 2 | fgdfgdfg | 12ч | 800 лей | 0 |
| 3 | dfgdfgdfgdfg| 12ч | 900 лей | 0 |
|^|^| Предварительный тест | 400 лей | 0 |
text text text text text text
I tried using this regexp: \|.+ but preg_match_all() simply dumps all the tables unseparated in the array. Any help, please? Thanks.
As i see, you have a set of tables within one string. And you need to split string to tables. I assume you could split the string with the text, separating tables.
Just like here: http://ideone.com/VCt4f (using this question). This will give you this:
When you’re done extracting tables you could simply split them to columns with