preg_match_all索引数组

时间:2012-10-21 03:52:37

标签: php multidimensional-array preg-match-all

$pattern='/(\/title\/tt\d{7}\/"[\s]+title=")([\/\(\)-:@!%*#=_|?$&;.\w\s]+?)(<)/um';
preg_match_all($pattern,$title[0],$anchor);
print_r ($anchor);

对于上面的代码,我得到一堆锚[0],锚[1],锚[2],锚[3]。

但是当我分开使用这些线时:

    print_r ($anchor[0]);
    echo "<br/>";
    print_r ($anchor[1]);
    echo "<br/>";
    print_r ($anchor[2]);

$ anchor [3]的输出被附加到相应的$ anchor [2]。

为什么会这样,我怎么能把它们分开呢?

它的var_dump($ anchor)如下(我知道很久)

array(4) { [0]=> array(49) { [0]=> string(67) "/title/tt0145487/" title="Spider-Man (2002)"><" [1]=> string(81) "/title/tt1872181/" title="The Amazing Spider-Man 2 (2014)"><" [2]=> string(69) "/title/tt0316654/" title="Spider-Man 2 (2004)"><" [3]=> string(69) "/title/tt0413300/" title="Spider-Man 3 (2007)"><" [4]=> string(86) "/title/tt1722512/" title="Ultimate Spider-Man (2012 TV Series)"><" [5]=> string(86) "/title/tt2016724/" title="Ultimate Spider-Man (2012 TV Series)"><" [6]=> string(98) "/title/tt0112175/" title="Spider-Man: The Animated Series (1994 TV Series)"><" [7]=> string(98) "/title/tt0706875/" title="Spider-Man: The Animated Series (1994 TV Series)"><" [8]=> string(77) "/title/tt0100669/" title="Spiderman (1990 Short Film)"><" [9]=> string(81) "/title/tt0594909/" title="HBO First Look (1992 TV Series)"><" [10]=> string(81) "/title/tt0394608/" title="HBO First Look (1992 TV Series)"><" [11]=> string(89) "/title/tt1972762/" title="CollegeHumor Originals (2006 TV Series)"><" [12]=> string(93) "/title/tt0976192/" title="The Spectacular Spider-Man (2008 TV Series)"><" [13]=> string(92) "/title/tt2056702/" title="Spider-Man XXX: A Porn Parody (2011 Video)"><" [14]=> string(92) "/title/tt1246781/" title="The Angry Video Game Nerd (2006 TV Series)"><" [15]=> string(87) "/title/tt1832811/" title="The Nostalgia Critic (2007 TV Series)"><" [16]=> string(77) "/title/tt0290983/" title="Spider-Man (2003 TV Series)"><" [17]=> string(77) "/title/tt0706896/" title="Spider-Man (2003 TV Series)"><" [18]=> string(88) "/title/tt2218492/" title="Big Morning Buzz Live (2011 TV Series)"><" [19]=> string(90) "/title/tt2249079/" title="The Amazing Spider-Man (2012 Video Game)"><" [20]=> string(89) "/title/tt0076975/" title="The Amazing Spider-Man (1977 TV Series)"><" [21]=> string(79) "/title/tt2312692/" title="Cupcake Wars (2009 TV Series)"><" [22]=> string(103) "/title/tt1805858/" title="Special Collector&#x27;s Edition (2010 TV Series)"><" [23]=> string(101) "/title/tt0083481/" title="Spider-Man and His Amazing Friends (1981 TV Series)"><" [24]=> string(101) "/title/tt0804166/" title="Spider-Man and His Amazing Friends (1981 TV Series)"><" [25]=> string(77) "/title/tt0061301/" title="Spider-Man (1967 TV Series)"><" [26]=> string(77) "/title/tt0826480/" title="Spider-Man (1967 TV Series)"><" [27]=> string(77) "/title/tt0827431/" title="Spider-Man (1967 TV Series)"><" [28]=> string(77) "/title/tt0824199/" title="Spider-Man (1967 TV Series)"><" [29]=> string(77) "/title/tt0826474/" title="Spider-Man (1967 TV Series)"><" [30]=> string(77) "/title/tt0826475/" title="Spider-Man (1967 TV Series)"><" [31]=> string(79) "/title/tt1298456/" title="Troldspejlet (1989 TV Series)"><" [32]=> string(97) "/title/tt2084949/" title="Superman, Spiderman or Batman (2011 Short Film)"><" [33]=> string(82) "/title/tt1779548/" title="5 Second Movies (2007 TV Series)"><" [34]=> string(82) "/title/tt1779547/" title="5 Second Movies (2007 TV Series)"><" [35]=> string(82) "/title/tt1776372/" title="5 Second Movies (2007 TV Series)"><" [36]=> string(81) "/title/tt2250912/" title="The Amazing Spider-Man 3 (????)"><" [37]=> string(86) "/title/tt2008370/" title="The Nostalgia Chick (2008 TV Series)"><" [38]=> string(100) "/title/tt1629701/" title="Spider-Man: Shattered Dimensions (2010 Video Game)"><" [39]=> string(80) "/title/tt0411906/" title="Spider-Man 2 (2004 Video Game)"><" [40]=> string(80) "/title/tt0837564/" title="Spider-Man 3 (2007 Video Game)"><" [41]=> string(87) "/title/tt0207120/" title="Spider-Man Unlimited (1999 TV Series)"><" [42]=> string(91) "/title/tt2201697/" title="How It Should Have Ended (2005 TV Series)"><" [43]=> string(118) "/title/tt1132238/" title="Fighting, Flying and Driving: The Stunts of Spiderman 3 (2007 Video)"><" [44]=> string(87) "/title/tt2211391/" title="Atop the Fourth Wall (2008 TV Series)"><" [45]=> string(87) "/title/tt2318883/" title="Atop the Fourth Wall (2008 TV Series)"><" [46]=> string(87) "/title/tt2423022/" title="Atop the Fourth Wall (2008 TV Series)"><" [47]=> string(87) "/title/tt2063992/" title="Atop the Fourth Wall (2008 TV Series)"><" [48]=> string(87) "/title/tt1874973/" title="Atop the Fourth Wall (2008 TV Series)"><" } [1]=> array(49) { [0]=> string(36) "/title/tt0145487/" title="" [1]=> string(36) "/title/tt1872181/" title="" [2]=> string(36) "/title/tt0316654/" title="" [3]=> string(36) "/title/tt0413300/" title="" [4]=> string(36) "/title/tt1722512/" title="" [5]=> string(36) "/title/tt2016724/" title="" [6]=> string(36) "/title/tt0112175/" title="" [7]=> string(36) "/title/tt0706875/" title="" [8]=> string(36) "/title/tt0100669/" title="" [9]=> string(36) "/title/tt0594909/" title="" [10]=> string(36) "/title/tt0394608/" title="" [11]=> string(36) "/title/tt1972762/" title="" [12]=> string(36) "/title/tt0976192/" title="" [13]=> string(36) "/title/tt2056702/" title="" [14]=> string(36) "/title/tt1246781/" title="" [15]=> string(36) "/title/tt1832811/" title="" [16]=> string(36) "/title/tt0290983/" title="" [17]=> string(36) "/title/tt0706896/" title="" [18]=> string(36) "/title/tt2218492/" title="" [19]=> string(36) "/title/tt2249079/" title="" [20]=> string(36) "/title/tt0076975/" title="" [21]=> string(36) "/title/tt2312692/" title="" [22]=> string(36) "/title/tt1805858/" title="" [23]=> string(36) "/title/tt0083481/" title="" [24]=> string(36) "/title/tt0804166/" title="" [25]=> string(36) "/title/tt0061301/" title="" [26]=> string(36) "/title/tt0826480/" title="" [27]=> string(36) "/title/tt0827431/" title="" [28]=> string(36) "/title/tt0824199/" title="" [29]=> string(36) "/title/tt0826474/" title="" [30]=> string(36) "/title/tt0826475/" title="" [31]=> string(36) "/title/tt1298456/" title="" [32]=> string(36) "/title/tt2084949/" title="" [33]=> string(36) "/title/tt1779548/" title="" [34]=> string(36) "/title/tt1779547/" title="" [35]=> string(36) "/title/tt1776372/" title="" [36]=> string(36) "/title/tt2250912/" title="" [37]=> string(36) "/title/tt2008370/" title="" [38]=> string(36) "/title/tt1629701/" title="" [39]=> string(36) "/title/tt0411906/" title="" [40]=> string(36) "/title/tt0837564/" title="" [41]=> string(36) "/title/tt0207120/" title="" [42]=> string(36) "/title/tt2201697/" title="" [43]=> string(36) "/title/tt1132238/" title="" [44]=> string(36) "/title/tt2211391/" title="" [45]=> string(36) "/title/tt2318883/" title="" [46]=> string(36) "/title/tt2423022/" title="" [47]=> string(36) "/title/tt2063992/" title="" [48]=> string(36) "/title/tt1874973/" title="" } [2]=> array(49) { [0]=> string(27) "Spider-Man (2002)">" [1]=> string(41) "The Amazing Spider-Man 2 (2014)">" [2]=> string(29) "Spider-Man 2 (2004)">" [3]=> string(29) "Spider-Man 3 (2007)">" [4]=> string(46) "Ultimate Spider-Man (2012 TV Series)">" [5]=> string(46) "Ultimate Spider-Man (2012 TV Series)">" [6]=> string(58) "Spider-Man: The Animated Series (1994 TV Series)">" [7]=> string(58) "Spider-Man: The Animated Series (1994 TV Series)">" [8]=> string(37) "Spiderman (1990 Short Film)">" [9]=> string(41) "HBO First Look (1992 TV Series)">" [10]=> string(41) "HBO First Look (1992 TV Series)">" [11]=> string(49) "CollegeHumor Originals (2006 TV Series)">" [12]=> string(53) "The Spectacular Spider-Man (2008 TV Series)">" [13]=> string(52) "Spider-Man XXX: A Porn Parody (2011 Video)">" [14]=> string(52) "The Angry Video Game Nerd (2006 TV Series)">" [15]=> string(47) "The Nostalgia Critic (2007 TV Series)">" [16]=> string(37) "Spider-Man (2003 TV Series)">" [17]=> string(37) "Spider-Man (2003 TV Series)">" [18]=> string(48) "Big Morning Buzz Live (2011 TV Series)">" [19]=> string(50) "The Amazing Spider-Man (2012 Video Game)">" [20]=> string(49) "The Amazing Spider-Man (1977 TV Series)">" [21]=> string(39) "Cupcake Wars (2009 TV Series)">" [22]=> string(63) "Special Collector&#x27;s Edition (2010 TV Series)">" [23]=> string(61) "Spider-Man and His Amazing Friends (1981 TV Series)">" [24]=> string(61) "Spider-Man and His Amazing Friends (1981 TV Series)">" [25]=> string(37) "Spider-Man (1967 TV Series)">" [26]=> string(37) "Spider-Man (1967 TV Series)">" [27]=> string(37) "Spider-Man (1967 TV Series)">" [28]=> string(37) "Spider-Man (1967 TV Series)">" [29]=> string(37) "Spider-Man (1967 TV Series)">" [30]=> string(37) "Spider-Man (1967 TV Series)">" [31]=> string(39) "Troldspejlet (1989 TV Series)">" [32]=> string(57) "Superman, Spiderman or Batman (2011 Short Film)">" [33]=> string(42) "5 Second Movies (2007 TV Series)">" [34]=> string(42) "5 Second Movies (2007 TV Series)">" [35]=> string(42) "5 Second Movies (2007 TV Series)">" [36]=> string(41) "The Amazing Spider-Man 3 (????)">" [37]=> string(46) "The Nostalgia Chick (2008 TV Series)">" [38]=> string(60) "Spider-Man: Shattered Dimensions (2010 Video Game)">" [39]=> string(40) "Spider-Man 2 (2004 Video Game)">" [40]=> string(40) "Spider-Man 3 (2007 Video Game)">" [41]=> string(47) "Spider-Man Unlimited (1999 TV Series)">" [42]=> string(51) "How It Should Have Ended (2005 TV Series)">" [43]=> string(78) "Fighting, Flying and Driving: The Stunts of Spiderman 3 (2007 Video)">" [44]=> string(47) "Atop the Fourth Wall (2008 TV Series)">" [45]=> string(47) "Atop the Fourth Wall (2008 TV Series)">" [46]=> string(47) "Atop the Fourth Wall (2008 TV Series)">" [47]=> string(47) "Atop the Fourth Wall (2008 TV Series)">" [48]=> string(47) "Atop the Fourth Wall (2008 TV Series)">" } [3]=> array(49) { [0]=> string(4) "<" [1]=> string(4) "<" [2]=> string(4) "<" [3]=> string(4) "<" [4]=> string(4) "<" [5]=> string(4) "<" [6]=> string(4) "<" [7]=> string(4) "<" [8]=> string(4) "<" [9]=> string(4) "<" [10]=> string(4) "<" [11]=> string(4) "<" [12]=> string(4) "<" [13]=> string(4) "<" [14]=> string(4) "<" [15]=> string(4) "<" [16]=> string(4) "<" [17]=> string(4) "<" [18]=> string(4) "<" [19]=> string(4) "<" [20]=> string(4) "<" [21]=> string(4) "<" [22]=> string(4) "<" [23]=> string(4) "<" [24]=> string(4) "<" [25]=> string(4) "<" [26]=> string(4) "<" [27]=> string(4) "<" [28]=> string(4) "<" [29]=> string(4) "<" [30]=> string(4) "<" [31]=> string(4) "<" [32]=> string(4) "<" [33]=> string(4) "<" [34]=> string(4) "<" [35]=> string(4) "<" [36]=> string(4) "<" [37]=> string(4) "<" [38]=> string(4) "<" [39]=> string(4) "<" [40]=> string(4) "<" [41]=> string(4) "<" [42]=> string(4) "<" [43]=> string(4) "<" [44]=> string(4) "<" [45]=> string(4) "<" [46]=> string(4) "<" [47]=> string(4) "<" [48]=> string(4) "<" } }

0 个答案:

没有答案