duanning9110 2015-09-04 19:41
浏览 94
已采纳

无法获得preg匹配以在两个书挡字符串之间工作

I'm trying to get all the text between the two == Quotes == but I'm having trouble getting preg_match to return anything other than null, my code is:

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]]

  • 写回答

2条回答 默认 最新

  • dongyi2993 2015-09-04 19:58
    关注

    You need to use the s modifier so the . matches new lines as well. I'd also recommend using preg_match_all in case there are multiples of those quotes in your string. Oh, I also added a capture group to capture the value between the == 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]);
    

    Output:

    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 Demo: https://regex101.com/r/nR9mL7/1

    More on modifiers: http://php.net/manual/en/reference.pcre.pattern.modifiers.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题