C
C
chief2016-12-07 04:26:50
PHP
chief, 2016-12-07 04:26:50

PHP. preg_match_all how to do nested parsing?

Greetings. I'm new to RNR. I'm learning. I want to make a text parser with a record in the database according to the conditions. I figured out the principle of the function, but I just can’t move further, here’s where:
INTRODUCTION INFO:
There is the following text: (input was made by POST c TEXTAREA )

Yanitic:ачив не найдено

yurahm: медаль золото(23:10 12-12-2014)
59д Жертвам Голодомору(T2617, Voronovytsya, Chernivets' ka oblast, Ukraine) https://www.ingress.com/intel?ll=48.530544,26.64706&z=17&pll=48.530544,26.64706
59д Памятник Неизвестного Солдату (Unnamed Road, Sokil, Khmel' nyts' ka oblast, Ukraine) https://www.ingress.com/intel?ll=48.529953,26.645298&z=17&pll=48.529953,26.645298
58д Капличка(Unnamed Road, Ruda, Khmel' nyts' ka oblast, Ukraine) https://www.ingress.com/intel?ll=48.555892,26.567197&z=17&pll=48.555892,26.567197
39д Олень(E50, Vinnyts' ka oblast, Ukraine) https://www.ingress.com/intel?ll=49.366811,27.984859&z=17&pll=49.366811,27.984859
39д Сержант Петренко(E50, Vinnyts' ka oblast, Ukraine) https://www.ingress.com/intel?ll=49.366651,27.985773&z=17&pll=49.366651,27.985773
32д Собор Святого Михаїла(Olimpiiska St, Khmelnytskyi, Khmel' nyts' ka oblast, Ukraine) https://www.ingress.com/intel?ll=49.435902,26.958889&z=17&pll=49.435902,26.958889
15д Стадиончик(Lyali Ratushnoi Street, 128, Vinnytsia, Vinnyts' ka oblast, Ukraine) https://www.ingress.com/intel?ll=49.221695,28.433667&z=17&pll=49.221695,28.433667

zZHunteRZz:ачив не найдено

zZWehrZz:ачив не найдено
GhostPathfinder: медаль золото(03:19 19-02-2016)
54д памятник Володарскому(Н03, Khmel' nyts' ka oblast, Ukraine) https://www.ingress.com/intel?ll=49.806018,27.56081&z=17&pll=49.806018,27.56081
54д церковь(Н03, Khmel' nyts' ka oblast, Ukraine) https://www.ingress.com/intel?ll=49.806456,27.561546&z=17&pll=49.806456,27.561546
54д Павшим В Боях(Н03, Krasnoselka, Zhytomyrs' ka oblast, Ukraine) https://www.ingress.com/intel?ll=49.989098,28.000007&z=17&pll=49.989098,28.000007
54д Часовня на перекрёстке(E101, Chernihivs' ka oblast, Ukraine) https://www.ingress.com/intel?ll=51.139195,31.862377&z=17&pll=51.139195,31.862377
54д Прокопович Петр Иванович(E101, Chernihivs' ka oblast, Ukraine) https://www.ingress.com/intel?ll=51.298025,32.770144&z=17&pll=51.298025,32.770144

1д Filarmoniya(Haharina street, 5, Khmelnytskyi, Khmel' nyts' ka oblast, Ukraine) https://www.ingress.com/intel?ll=49.418876,26.976199&z=17&pll=49.418876,26.976199

This is a list of Players and portals captured by them with coordinates (map link).
It is necessary that the arsil script writes all the listed information to the database, but ran into a problem: The player's name is written only once and the list of portals is below. By line-by-line parsing, I can (and can) output (and do something) only with those who have one line: no achievements.
And how to make those who have a large list added to the database with a nickname? I can add line by line, but without a nickname.
Tried to do nested instructions, but it doesn't work.
Tell me how to tell the function that if the line with the nickname and info about the medal - then parse the following lines up to the next nickname (or the second reset of the line, it is like an indent in the text), or at the end of the line "4 numbers and an empty next line". I tried s, \z, \Z, m (^ and $ put in expressions) but it doesn't work.
Help me please.
Here is the script
76e464a8420349b1a7fdc695167a0860.PNG

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ramil, 2016-12-07
Abdrahimov @MrAbdrahimov

I would pervert like this:
Line by line looking for the presence of " https://www.ingress.com/intel " in the line.
If it is not found, then from this line we parse the achievement with the date or "achievement not found"
from all subsequent lines in which " https://www.ingress.com/intel " is found We take the list of portals assigned to the last found user into the database .

for($i=0;$i<count($list);$i++){
      if(stristr($list[$i], 'https://www.ingress.com/intel') === FALSE) {
            $login = 'парсим логин с $list[$i] и присваеваем';
      } else {
            $port = 'парсим данные портала и прочее с $list[$i]';
      }
      Кладём в БД $login $port;
}

Thus, we will shovel all the lines and put all the information in the database. You only need to clean $list[] from empty values ​​or filter it.
ps $list[] - list of received text strings.

R
Ravshan Abdulaev, 2016-12-07
@ravshanium

It seems not difficult:
https://regex101.com/r/272lAq/1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question