pplexr Posted June 4, 2007 Share Posted June 4, 2007 hi, i am using this regex to extract some content form a html page but this regex dont work and give me Warning: ereg() [function.ereg]: REG_BADRPT and i tested this code with regexbuddy and it was correct i think maybe its because i should use preg instead of ereg .but i dont know how to do this here is the regex $content="html content here"; $pat = '<div id="Body"><p>([\w\W]+)(?:<h3>Related stories</h3>|</div>(?:[\w\W]*)<div id="RelatedStories">)'; $regs = array(); if(ereg($pat,$content,$regs)) { $content=$regs[0]; } thanks, Quote Link to comment Share on other sites More sharing options...
Wildbug Posted June 5, 2007 Share Posted June 5, 2007 Your pattern is devised for the PCRE functions; not ereg. Try using preg_match or preg_match_all. Quote Link to comment Share on other sites More sharing options...
pplexr Posted June 5, 2007 Author Share Posted June 5, 2007 i tried preg_match and preg_match_all but i got this Warning Warning: preg_match_all() [function.preg-match-all]: Unknown modifier '<' any idea? Quote Link to comment Share on other sites More sharing options...
Wildbug Posted June 5, 2007 Share Posted June 5, 2007 Yeah, you need delimiters. Read the PCRE Syntax section for more info. $content="html content here"; $pat = '/<div id="Body"><p>(.+?)(?:<h3>Related stories<\/h3>|<\/div>.*?<div id="RelatedStories">)/is'; preg_match_all($pat,$content,$matches,PREG_SET_ORDER); foreach ($matches as $match) echo "$match[1]<br>\n"; // or whatever You only want to capture this part "(.+?)", right? Quote Link to comment Share on other sites More sharing options...
pplexr Posted June 6, 2007 Author Share Posted June 6, 2007 Yeah, you need delimiters. Read the PCRE Syntax section for more info. $content="html content here"; $pat = '/<div id="Body"><p>(.+?)(?:<h3>Related stories<\/h3>|<\/div>.*?<div id="RelatedStories">)/is'; preg_match_all($pat,$content,$matches,PREG_SET_ORDER); foreach ($matches as $match) echo "$match[1]<br>\n"; // or whatever You only want to capture this part "(.+?)", right? i tried ur code but i got Warning: preg_replace() [function.preg-replace]: Unknown modifier '(' and yes i want to capture "(.+?)" thanks anyway, Quote Link to comment Share on other sites More sharing options...
Wildbug Posted June 6, 2007 Share Posted June 6, 2007 It works fine for me. Are you sure you used it verbatim, or did you modify it? Quote Link to comment Share on other sites More sharing options...
pplexr Posted June 7, 2007 Author Share Posted June 7, 2007 well i tried the code alone and it worked fine but when i put it in my script it gives me this error ..anyway i will try to fix this thanks alot, Wildbug 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.