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. Link to comment https://forums.phpfreaks.com/topic/132444-solved-preg_match-problem/ 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> Link to comment https://forums.phpfreaks.com/topic/132444-solved-preg_match-problem/#findComment-688630 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 Link to comment https://forums.phpfreaks.com/topic/132444-solved-preg_match-problem/#findComment-689998 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, Link to comment https://forums.phpfreaks.com/topic/132444-solved-preg_match-problem/#findComment-690000 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> Link to comment https://forums.phpfreaks.com/topic/132444-solved-preg_match-problem/#findComment-690185 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 Link to comment https://forums.phpfreaks.com/topic/132444-solved-preg_match-problem/#findComment-690227 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 ??? Link to comment https://forums.phpfreaks.com/topic/132444-solved-preg_match-problem/#findComment-690783 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 Link to comment https://forums.phpfreaks.com/topic/132444-solved-preg_match-problem/#findComment-692073 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.