omfgthezerg Posted February 6, 2009 Share Posted February 6, 2009 Hello, I'm trying to extract a certain part of a string but having some issues. Regex Code: preg_match_all("/\<div class='toggler'\>([\w\d]+)\<\/div\>.*(\<div class='modelPickerItem'\>.*\<\/ul\>\<\/div\>(?:\<div class='cleanup'\>(?:\<\/div\>)+)+(?:\<div class='toggler'\>)?)+/U", $nolines, $results); String tested using: $nolines = "<div class='toggler'>Berlingo</div><div class=\"element\"><div><h3 class=\"modelDate\">1996 on</h3><div style=\"_height:1px;\"><div class='modelPickerItem'><a class='modelName' href=\"/vans/reviews/citroen/berlingo-2002.aspx\"> 2002 on </a><div style=\"float:left; margin-right: 10px\"><a href=\"/vans/reviews/citroen/berlingo-2002.aspx\"><img class=\"modelListImage\" src='/imagecache/file/160x100/archive/LCV/Citroen/Berlingo_comm/IMG_3885.JPG' /></a></div><div class=\"modelDetails\"><ul class='forAgainst'><li class='plus'>Perhaps the best all-round small van</li><li class='minus'>Not as clever as newer rivals</li></ul></div><div class='cleanup'></div></div><div class='cleanup'></div><div class='modelPickerItem'><a class='modelName' href=\"/vans/reviews/citroen/berlingo-2008.aspx\"> 2008 on </a><div style=\"float:left; margin-right: 10px\"><a href=\"/vans/reviews/citroen/berlingo-2008.aspx\"><img class=\"modelListImage\" src='/imagecache/file/160x100/archive/LCV/Citroen/Berlingo (08-)/2953.jpg' /></a></div><div class=\"modelDetails\"><ul class='forAgainst'><li class='plus'>All-round improvements over previous van, versatile features</li><li class='minus'>Lower power versions feel sluggish.</li></ul></div><div class='cleanup'></div></div><div class='cleanup'></div></div><div class='cleanup'></div></div></div><div class='toggler'>"; Expected result: array(3) { [0]=> array(1) { [0]=> string(642) "<div class='toggler'>Berlingo</div><div class="element"><div><h3 class="modelDate">1996 on</h3><div style="_height:1px;"><div class='modelPickerItem'><a class='modelName' href="/vans/reviews/citroen/berlingo-2002.aspx"> 2002 on </a><div style="float:left; margin-right: 10px"><a href="/vans/reviews/citroen/berlingo-2002.aspx"><img class="modelListImage" src='/imagecache/file/160x100/archive/LCV/Citroen/Berlingo_comm/IMG_3885.JPG' /></a></div><div class="modelDetails"><ul class='forAgainst'><li class='plus'>Perhaps the best all-round small van</li><li class='minus'>Not as clever as newer rivals</li></ul></div><div class='cleanup'></div>" } [1]=> array(1) { [0]=> string( "Berlingo" } [2]=> array(1) { [0]=> string(521) "<div class='modelPickerItem'><a class='modelName' href="/vans/reviews/citroen/berlingo-2002.aspx"> 2002 on </a><div style="float:left; margin-right: 10px"><a href="/vans/reviews/citroen/berlingo-2002.aspx"><img class="modelListImage" src='/imagecache/file/160x100/archive/LCV/Citroen/Berlingo_comm/IMG_3885.JPG' /></a></div><div class="modelDetails"><ul class='forAgainst'><li class='plus'>Perhaps the best all-round small van</li><li class='minus'>Not as clever as newer rivals</li></ul></div><div class='cleanup'></div></div><div class='cleanup'></div>" [1]=> string(647) "<div class='modelPickerItem'><a class='modelName' href="/vans/reviews/citroen/berlingo-2008.aspx"> 2008 on </a><div style="float:left; margin-right: 10px"><a href="/vans/reviews/citroen/berlingo-2008.aspx"><img class="modelListImage" src='/imagecache/file/160x100/archive/LCV/Citroen/Berlingo (08-)/2953.jpg' /></a></div><div class="modelDetails"><ul class='forAgainst'><li class='plus'>All-round improvements over previous van, versatile features</li><li class='minus'>Lower power versions feel sluggish.</li></ul></div><div class='cleanup'></div></div><div class='cleanup'></div></div><div class='cleanup'></div></div></div><div class='toggler'>" } } Actual result: array(3) { [0]=> array(1) { [0]=> string(642) "<div class='toggler'>Berlingo</div><div class="element"><div><h3 class="modelDate">1996 on</h3><div style="_height:1px;"><div class='modelPickerItem'><a class='modelName' href="/vans/reviews/citroen/berlingo-2002.aspx"> 2002 on </a><div style="float:left; margin-right: 10px"><a href="/vans/reviews/citroen/berlingo-2002.aspx"><img class="modelListImage" src='/imagecache/file/160x100/archive/LCV/Citroen/Berlingo_comm/IMG_3885.JPG' /></a></div><div class="modelDetails"><ul class='forAgainst'><li class='plus'>Perhaps the best all-round small van</li><li class='minus'>Not as clever as newer rivals</li></ul></div><div class='cleanup'></div>" } [1]=> array(1) { [0]=> string( "Berlingo" } [2]=> array(1) { [0]=> string(521) "<div class='modelPickerItem'><a class='modelName' href="/vans/reviews/citroen/berlingo-2002.aspx"> 2002 on </a><div style="float:left; margin-right: 10px"><a href="/vans/reviews/citroen/berlingo-2002.aspx"><img class="modelListImage" src='/imagecache/file/160x100/archive/LCV/Citroen/Berlingo_comm/IMG_3885.JPG' /></a></div><div class="modelDetails"><ul class='forAgainst'><li class='plus'>Perhaps the best all-round small van</li><li class='minus'>Not as clever as newer rivals</li></ul></div><div class='cleanup'></div>" } } Thanks In advance. Quote Link to comment https://forums.phpfreaks.com/topic/144067-regex-help/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.