Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Can';t使preg match在两个bookend字符串之间工作_Php_Regex_Parsing_Preg Match - Fatal编程技术网

Php Can';t使preg match在两个bookend字符串之间工作

Php Can';t使preg match在两个bookend字符串之间工作,php,regex,parsing,preg-match,Php,Regex,Parsing,Preg Match,我正在尝试获取两个==Quotes==之间的所有文本,但我在获取preg\u match以返回除null以外的任何内容时遇到问题,我的代码是: preg_match('/== Quotes == .+ == Quotes/', $quotes_str, $matches); [[File:Charlie Chaplin.jpg | thumb | right |我只剩下一件事,而且只有一件事——那就是一个[[小丑]。这使我比任何[[政治家]]都处于一个更高的层次上。“[[w:Charlie C

我正在尝试获取两个
==Quotes==
之间的所有文本,但我在获取preg\u match以返回除null以外的任何内容时遇到问题,我的代码是:

preg_match('/== Quotes == .+ == Quotes/', $quotes_str, $matches);

[[File:Charlie Chaplin.jpg | thumb | right |我只剩下一件事,而且只有一件事——那就是一个[[小丑]。这使我比任何[[政治家]]都处于一个更高的层次上。“[[w:Charlie Chaplin | Charles Spencer Chaplin爵士]””,KBE([[1889]-[1977]]12月25日)是英国喜剧演员和导演,通常以他的艺名“查理·卓别林”而闻名。**=Quotes=**[[档案:查尔斯·卓别林1920.jpg |大拇指|对|我的神童【[sin]]过去是,现在仍然是一个不守旧的人。][[档案:查理·卓别林1914年初。gif |大拇指|对|我是什么样的人:一个[[个人]],独特而不同][[档案:查理·卓别林和甘地|大拇指|对|我是一个个人和一个自由的信徒]].这就是我所有的[[政治]][[档案:双阿拉斯加彩虹.jpg |拇指|对|仰望[[天空]]
如果你往下看,你永远找不到[[彩虹]
。]*'[[战争]],冲突,一切都是[[生意]]。“一个[[谋杀]]造就了一个[[恶棍]..*“摇摆高高的小女孩”,这是卓别林为1969年重新发行的[[w:马戏团(电影);“马戏团”(1928)]而创作和演唱的首歌[http://www.charliechaplin.com/biography/articles/84-Swing-little-girl 全文在线]*[[生活]]在特写镜头中是一场悲剧,但却是一场[[喜剧]]从长远来看。**据许多网站报道,卓别林在签署创建联合艺术家工作室(1919年)的文件时曾说过,这一说法被认为是源自一句关于“理查德·罗兰”(Metro Pictures的负责人)同一事件的评论:“疯子已经接管了收容所。”"''; 该声明的各种衍生或报告也包括“疯子已经接管了避难所”,据报道,对罗兰的归因至少早在1926年,在特里·拉姆赛的作品《一百万零一夜》中,以及最近在[http://www.variety.com/index.asp?layout=variety100&content=jump&jump=general&articleID=VR1117930598 《综艺》(2005年10月16日)**大卫·罗宾逊在《查理·卓别林:喜剧天才》(1996年)第57页中也声称,一位不满的电影发行商说“疯子正在接管精神病院。”*广泛归因于卓别林和其他一些人,为[http://quoteinvestigator.com/2011/07/16/laughter-day/ “引用调查者”中的“没有笑声的一天就是浪费的一天”表明,这种表达可以追溯到[[Nicolas Chamfort]]的表达,发表在[http://books.google.com/books?id=N3tBAAAAcAAJ&q=%22pas+ri%22#v=snippet&q=%22pas%20ri%22&f=false“历史、政治和沿海地区,尚福镇制造业外部最高标准”《法国水星》(1795年7月18日),第351页]:“La plus perdue de toutes les journées est celle oùl'on n'a pas ri.”早在F.Prevost和F.Blagdon的《文学之花》(1803)中的“笑”一文中就有这段英文译本:::我很佩服那个大声喊道:“我失去了一天!”因为在这过程中,他忽略了做任何好事;但另一个观察到“所有日子中最失落的,是我们没有笑过的日子”而且,我必须承认,我非常赞同他的观点。*当我开始爱自己的时候,我发现痛苦和情感上的痛苦只是一个警告信号,表明我在违背自己的[[真相]]生活。
今天,我知道,这是“真实性”。许多网站和博客引用了“查理·卓别林70岁生日的演讲”。[http://comoutrosolhos.multiply.com/journal/item/139 事实上,对Kim&Alison McMillen(2001)的《当我足够爱自己》一书中的一段文字进行了重新翻译(来自葡萄牙语BR)。{{{{misassessed end}}**==对卓别林的引用==**[[文件:香港迪士尼樂園 (24)JPG大拇指对,我们想要一些吸引人的东西,我们想到了一个有点像卓别林一样渴望的小老鼠——一个尽力做到最好的小家伙“查尔斯·卓别林是第一位敢于通过[讽刺]和嘲弄来揭露在20世纪四五十年代的冷战年代超越美国的偏执狂和[政治]不容忍的电影制片人。”*我们觉得公众,特别是[[儿童]],喜欢可爱和小的动物。[http://www.pbs.org/wnet/americanmasters/database/chaplin_c.html 美国大师:查理·卓别林]在PBS*[http://www.csse.monash.edu.au/~pringle/silent/chaplin/aaronhale.html简介][http://www.chaplinalife.com/ “卓别林:一种生活”{{DEFAULTSORT:卓别林,查理}}[[类别:英国人][[类别:英国演员]][[类别:喜剧演员][[类别:不可知论者][[类别:人文主义者][[类别:讽刺作家][[类别:电影导演][[类别:1970年代死亡]]

您需要使用
s
修饰符,以便
也匹配新行。我还建议使用
preg\u match\u all
以防字符串中有多个
引号。哦,我还添加了一个捕获组来捕获
==quotes=
之间的值

<?php
$string = "[[File:Charlie Chaplin.jpg|thumb|right|I remain just one thing, and one thing only — and that is a [[clown]]. It places me on a far higher plane than any [[politician]].]] '''[[w:Charlie Chaplin| Sir Charles Spencer Chaplin]]''', KBE ([[16 April]] [[1889]] – [[25 December]] [[1977]]) was a British comedic actor and director, usually known by his stage name of '''Charlie Chaplin'''. == Quotes == [[File:Charles-chaplin 1920.jpg|thumb|right|My prodigious [[sin]] was, and still is, being a non-conformist.]] [[File:Charlie chaplin early 1914.gif|thumb|right|I am what I am: an [[individual]], unique and different.]] [[File:CharlieChaplinAndGandhi.jpg |thumb|right|I am an individual and a [[believer]] in [[liberty]]. That is all the [[politics]] I have.]] [[File:Double-alaskan-rainbow.jpg|thumb|right|Look up to the [[sky]] 
You'll never find [[rainbows]] 
If you’re looking down.]] * '''[[Wars]], conflict, it's all [[business]]. \"One [[murder]] makes a [[villain]]. * \"Swing High Little Girl\", opening song written and sung by Chaplin for the 1969 re-release of [[w:The Circus (film)|''The Circus'' (1928)]] - [http://www.charliechaplin.com/biography/articles/84-Swing-little-girl Full text online] * [[Life]] is a tragedy when seen in close-up, but a [[comedy]] in long-shot. ** Reported by many sites to have been said by Chaplin upon signing the papers to create the United Artists studio (1919), this is believed to actually be derived from a remark about the same event attributed to '''Richard Rowland''', the head of Metro Pictures: ''\"The lunatics have taken charge of the asylum\"''; variant derivations or reports of this statement also include \"The lunatics have taken over the asylum\", and the attribution to Rowland is reported to have occurred at least as early as 1926, in the work ''A Million and One Nights'' by Terry Ramsaye, and as recently as in [http://www.variety.com/index.asp?layout=variety100&content=jump&jump=general&articleID=VR1117930598 ''Variety''] (16 October 2005) ** David Robinson In ''Charlie Chaplin: Comic Genius'' (1996), p. 57, also asserts that a disgruntled film distributor said \"The lunatics are taking over the asylum.\" * Widely attributed to Chaplin and a few others, research done for [http://quoteinvestigator.com/2011/07/16/laughter-day/ \"A Day Without Laughter is a Day Wasted\" at ''Quote Investigator''] indicate that such expressions date back to that of [[Nicolas Chamfort]], published in [http://books.google.com/books?id=N3tBAAAAcAAJ&q=%22pas+ri%22#v=snippet&q=%22pas%20ri%22&f=false \"Historique, Politique et Litteraire, Maximes détachées extraites des manuscrits de Champfort\" ''Mercure Français'' (18 July 1795), p. 351]: ''La plus perdue de toutes les journées est celle où l’on n’a pas ri.'' Translations of this into English have been found as early as one in \"Laughing\" in ''Flowers of Literature'' (1803) by F. Prevost and F. Blagdon : :: I admire the man who exclaimed, \“I have lost a day!\” because he had neglected to do any good in the course of it; but another has observed that \“'''the most lost of all days, is that in which we have not laughed''';\” and, I must confess, that I feel myself greatly of his opinion. * As I began to love myself I found that anguish and emotional suffering are only warning signs that I was living against my own [[truth]].
Today, I know, this is \“AUTHENTICITY\". Quoted by many sites and blogs as \"speech that Charlie Chaplin gave on his 70th birthday\". [http://comoutrosolhos.multiply.com/journal/item/139 Actually, a re-translation (from Portuguese-BR) of a text from the book \"When I Loved Myself Enough\" by Kim & Alison McMillen (2001).] {{Misattributed end}} == Quotes about Chaplin == [[File:香港迪士尼樂園 (24).JPG|thumb|right|We wanted something appealing, and we thought of a tiny bit of a [[mouse]] that would have something of the wistfulness of Chaplin — a little fellow trying to do the best he could. ~ [[Walt Disney]] ]] * '''With ''[[w:A King in New York|A King in New York]]'' Charles Chaplin was the first film-maker to dare to expose, through [[satire]] and ridicule, the paranoia and [[political]] intolerance which overtook the United States in the Cold War years of the 1940s and 50s.''' *We felt that the public, and especially the [[children]], like animals that are cute and little. [http://www.pbs.org/wnet/americanmasters/database/chaplin_c.html American Masters: Charlie Chaplin] at PBS * [http://www.csse.monash.edu.au/~pringle/silent/chaplin/aaronhale.html Brief bio] * [http://www.chaplinalife.com/ Tribute pages at ''Chaplin : A Life''] {{DEFAULTSORT:Chaplin, Charlie}} [[Category:English people]] [[Category:British actors]] [[Category:Comedians]] [[Category:Agnostics]] [[Category:Humanists]] [[Category:Satirists]] [[Category:Film directors]] [[Category:1970s deaths]]";
preg_match_all('/== Quotes == (.+?) == Quotes/s', $string, $matches);
print_r($matches[1]);
正则表达式101演示:


关于修饰语的更多信息:

查看你的
**==Quotes==**
**==Quotes关于卓别林===**

我相信你可能需要这个:

preg_match_all('#== Quotes[^=]+==(.+?)== Quotes[^=]+==#su', $quotes_str, $matches);
或者这个:

preg_match_all('#\*\*== Quotes[^=]+==\*\*(.+?)\*\*== Quotes[^=]+==\*\*#su', $quotes_str, $matches);

不幸的是,WikiQuoteAPI没有为我提供一种直接针对报价的方法。实际数据本身的大小大约是这个的两倍。
preg_match_all('#\*\*== Quotes[^=]+==\*\*(.+?)\*\*== Quotes[^=]+==\*\*#su', $quotes_str, $matches);