Home  >  Article  >  Backend Development  >  php正则表达式匹配一段中文,中间有换行,空白,应该怎么写?

php正则表达式匹配一段中文,中间有换行,空白,应该怎么写?

WBOY
WBOYOriginal
2016-06-06 20:28:271074browse

1、举个例子:

<code><div class="con">
    <p>
        小学生手册:<br>
        1、好好学习;<br>
        2、天天向上;<br>
    </p>
</div>
</code>

要把中间p标签中的内容抓出来,正则表达式应该怎么写?

回复内容:

1、举个例子:

<code><div class="con">
    <p>
        小学生手册:<br>
        1、好好学习;<br>
        2、天天向上;<br>
    </p>
</div>
</code>

要把中间p标签中的内容抓出来,正则表达式应该怎么写?

<code>$tmp = '<div class="con">
    <p>
        小学生手册:<br>
        1、好好学习;<br>
        2、天天向上;<br>
    </p>
</div>';

preg_match('/<p>(.*?)/s', $tmp, $ret);

echo $ret[1];</p></code>

请参看 PCRE_MULTILINE 模式修饰符 m
http://php.net/manual/zh/reference.pcre.pattern.modifiers.php

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn