Jump to content

REG_BADRPT with ereg


pplexr

Recommended Posts

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,

Link to comment
https://forums.phpfreaks.com/topic/54183-reg_badrpt-with-ereg/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/54183-reg_badrpt-with-ereg/#findComment-268571
Share on other sites

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,

Link to comment
https://forums.phpfreaks.com/topic/54183-reg_badrpt-with-ereg/#findComment-268991
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.