ted_chou12 Posted November 12, 2008 Share Posted November 12, 2008 I have a text: <h3 class="customize">title</h3> <p class="customize">content</p> <p class="post-footer align-right customize"> <span class="date">date</span> </p> I wish to extract the title, content and date individually, so far, I have got: preg_match_all("|<h3 class=\"customize\">(.*)?<\/h3>|U", $content, $result, PREG_PATTERN_ORDER); Which gets the title, but I cant do the same to get the content, does anyone know how? Thanks, Ted. Quote Link to comment Share on other sites More sharing options...
effigy Posted November 12, 2008 Share Posted November 12, 2008 <pre> <?php $data = <<<DATA <h3 class="customize">title</h3> <p class="customize">content</p> <p class="post-footer align-right customize"> <span class="date">date</span> </p> DATA; preg_match_all('/\sclass="(?:customize|date)">([^<]+)/', $data, $result, PREG_PATTERN_ORDER); print_r($result); ?> </pre> Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted November 14, 2008 Author Share Posted November 14, 2008 Hello , thanks for the solution, the starting code tag works very well, but the content stops at <br /> An example of the content that I have is: <h3 class="customize">title</h3> <p class="customize">content<br /> blah blah .... <a href=""></a><img src />...</p> <p class="post-footer align-right customize"> <span class="date">date</span> </p> But it can only stop at </p> Thanks again, Ted Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted November 14, 2008 Author Share Posted November 14, 2008 I came up with some random codes preg_match_all('/\sclass="(?:customize|date)">(.*)?<\/(p|span)>/', $content, $array1, PREG_PATTERN_ORDER); hope it gives some ideas, Quote Link to comment Share on other sites More sharing options...
effigy Posted November 14, 2008 Share Posted November 14, 2008 <pre> <?php $data = <<<DATA <h3 class="customize">title</h3> <p class="customize">content</p> <p class="post-footer align-right customize"> <span class="date">date</span> </p> DATA; preg_match_all('%<(\w+)[^>]+class="(?:customize|date)">(.*?)</\1>%', $data, $result, PREG_PATTERN_ORDER); print_r($result); ?> </pre> Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted November 14, 2008 Author Share Posted November 14, 2008 Hi, I got this error: Warning: preg_match_all() [function.preg-match-all]: Unknown modifier '\' in /home/user/public_html/blog_feed.php on line 29 when I was trying to correct it. Thanks, Ted Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted November 15, 2008 Author Share Posted November 15, 2008 Hello, my bad, there was no error, I think I accidentally deleted something in there, but that expression gives span in the </span> tag, I dont understand ??? Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted November 17, 2008 Author Share Posted November 17, 2008 I got it~ preg_match_all("/<(?|span|h3)\sclass=\"(?:customize|date)\">(.*?)<\/(?|span|h3)>/", $content, $array1, PREG_PATTERN_ORDER); Ted 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.