H
H
hdtor2016-04-08 13:44:58
PHP
hdtor, 2016-04-08 13:44:58

How to fix regex?

$text = '<li class=" default-news-list">
     
                                            <a href="news/showNews.do?sud_ponoviv_na_posadi_ekszastupnika_nachalnika_golovnogo_slidchogo_upravlinnya_natspolitsiyi&objectId=1388205" >
                                              <div class="time">13:31</div>
                                                <div class="news-title">
                                                            Суд поновив на посаді екс-заступника начальника головного слідчого управління Нацполіції
                                                </div>
                                            </a>
                                            </li>';
     
    preg_match('#<li class=" default-news-list">(.*?)</li>#', $text, $var);
     
    var_dump($var);

You need to rip out the link and the title. Wrote this regex, well, something doesn't work. Who can help?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Osher, 2016-04-08
@miraage

Stop writing nonsense.
Symfony DomCrawler .

I
IllusionTurtle, 2016-04-08
@IllusionTurtle

preg_match('#(.*?)#s', $text, $var);
add the s modifier
php.net/manual/ru/reference.pcre.pattern.modifiers.php
s (PCRE_DOTALL)
If this modifier is used, the "dot" metacharacter in the pattern matches all characters, including newlines. Without it - everything, except for newlines. This modifier is equivalent to /s in Perl. A negated character class, such as [^a], always matches a newline, regardless of the presence of this modifier.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question