不能让两个书端字符串之间的preg匹配工作


Can't get preg match to work between two bookend strings

我试图获得两个== Quotes ==之间的所有文本,但我有麻烦让preg_match返回除null以外的任何东西,我的代码是:

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

[[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]] <br> You'll never find [[rainbows]] <br> 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]].<br>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]]

您需要使用s修饰符,以便.也匹配新行。我还建议使用preg_match_all,以防在你的字符串中有多个quotes。哦,我还添加了一个捕获组来捕获== 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]);
输出:

Array
(
    [0] => [[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}}
)

Regex 101演示:https://regex101.com/r/nR9mL7/1

关于修饰符的更多信息:http://php.net/manual/en/reference.pcre.pattern.modifiers.php

看你的**== Quotes ==****== Quotes about Chaplin ==**

我相信你可能需要这个:

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

或:

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