thegman Posted January 17, 2008 Share Posted January 17, 2008 Hi All, I need to remove all divs which have 'style="DISPLAY: none" '. <DIV id=radiobtn31 g="1">Hosting Required <DIV id=radiobtn3100 g="2"> Plan A - 3.99/month <DIV id=radiobtn321 g="3"> 1 Year</DIV> <DIV id=radiobtn322 style="DISPLAY: none" g="3"> 2 Years</DIV> </DIV> <DIV id=radiobtn3101 style="DISPLAY: none" g="2"> Plan B - 8.99/month <DIV id=radiobtn323 style="DISPLAY: none" g="3"> 1 Year</DIV> <DIV id=radiobtn324 style="DISPLAY: none" g="3"> 2 Years</DIV> </DIV> <DIV id=radiobtn3102 style="DISPLAY: none" g="2"> Plan C - 15.99/month <DIV id=radiobtn325 style="DISPLAY: none" g="3"> 1 Year</DIV> <DIV id=radiobtn326 style="DISPLAY: none" g="3"> 2 Years</DIV> </DIV> </DIV> Since they are nested, I tried deleting them inside out ie. Divs with g=3 first then g=2 and so on. The problem I encounter is after ejecting the div with g=3 i get the div with g=2 on different lines eg. <DIV id=radiobtn3102 style="DISPLAY: none" g="2"> Plan C - 15.99/month </DIV> Now, when i try to do the same for g=2 i get an error since the start and end tags are on different lines. The code I am using is as follows...but it just doesnt seem to work $string = preg_replace("<DIV.*DISPLAY.*none.*g=\"3\".*/DIV>", "", $string); $string = preg_replace("<DIV.*DISPLAY.*none.*g=\"2\".*/DIV>", "", $string); echo $string; I am a n00b at this and would appreciate any and all help in this regard. Many Thanks and best regards, G Quote Link to comment Share on other sites More sharing options...
effigy Posted January 17, 2008 Share Posted January 17, 2008 You need the /s modifier to include new lines in .. <pre> <?php $string = <<<DATA <DIV id=radiobtn31 g="1">Hosting Required <DIV id=radiobtn3100 g="2"> Plan A - 3.99/month <DIV id=radiobtn321 g="3"> 1 Year</DIV> <DIV id=radiobtn322 style="DISPLAY: none" g="3"> 2 Years</DIV> </DIV> <DIV id=radiobtn3101 style="DISPLAY: none" g="2"> Plan B - 8.99/month <DIV id=radiobtn323 style="DISPLAY: none" g="3"> 1 Year</DIV> <DIV id=radiobtn324 style="DISPLAY: none" g="3"> 2 Years</DIV> </DIV> <DIV id=radiobtn3102 style="DISPLAY: none" g="2"> Plan C - 15.99/month <DIV id=radiobtn325 style="DISPLAY: none" g="3"> 1 Year</DIV> <DIV id=radiobtn326 style="DISPLAY: none" g="3"> 2 Years</DIV> </DIV> </DIV> DATA; $string = preg_replace('%<DIV[^>]+DISPLAY[^>]+none[^>]+g="3"[^>]*>.*?</DIV>%s', '', $string); $string = preg_replace('%<DIV[^>]+DISPLAY[^>]+none[^>]+g="2"[^>]*>.*?</DIV>%s', '', $string); echo htmlspecialchars($string); ?> </pre> Quote Link to comment Share on other sites More sharing options...
thegman Posted January 17, 2008 Author Share Posted January 17, 2008 Dear effigy, I had been struggling with the code for almost 3 days and it was driving me insane. Your solution works perfectly I cant put into words how much I appreciate your help with this....but ill try... THANK YOU!THANK YOU!THANK YOU!THANK YOU!THANK YOU!THANK YOU!THANK YOU!...you rock man! Quote Link to comment 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.