PHP preg_match(.*)与过去的换行符不匹配 [英] PHP preg_match (.*) not matching past line breaks
本文介绍了PHP preg_match(.*)与过去的换行符不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在LONGTEXT列中有此数据(因此保留了换行符):
I have this data in a LONGTEXT column (so the line breaks are retained):
Paragraph one
Paragraph two
Paragraph three
Paragraph four
我正在尝试匹配第1到第3段.我正在使用以下代码:
I'm trying to match paragraph 1 through 3. I'm using this code:
preg_match('/Para(.*)three/', $row['file'], $m);
这不返回任何内容.如果我尝试通过以下方式在段落的第一行中工作:
This returns nothing. If I try to work just within the first line of the paragraph, by matching:
preg_match('/Para(.*)one/', $row['file'], $m);
然后代码工作,我得到正确的字符串返回.我在这里做什么错了?
Then the code works and I get the proper string returned. What am I doing wrong here?
推荐答案
使用s
修饰符.
preg_match('/Para(.*)three/s', $row['file'], $m);
http://php.net/manual/en/reference.pcre.pattern.modifiers .php
这篇关于PHP preg_match(.*)与过去的换行符不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文