eregi("<b class=author>(.*?)</b>", $content, $author) PHP: returns Warning: eregi(): REG_BADRPT in i am trying to get the result for the first closing tag for </b> if i do eregi("<b class=author>(.*)</b>", $content, $author) PHP: i get all the stuff until the final </b> closing tag.
Did you try escaping the "<" ? I had some problems with regexing the "<" character using the MT regex plugin yesterday. Sorry... just shooting from the hip. It looks like it should be valid on the surface to me.
You don't need the question mark. Try this instead: $content = "read this great book by <b class=author>robert crais</b> at my website"; eregi('<b class=author>(.*)</b>', $content, $author); print_r($author); PHP: Also, unless you have a reason for using the ereg functions for regular expression matching, try using the preg ones instead. They are a lot more powerful and faster in most cases.
sure that seems to work fine if there are no other instance of the closing </b> for example : $content = "read this great book by <b class=author>robert crais</b> at my website <b>this is where it errors</b>"; eregi('<b class=author>(.*)</b>', $content, $author); print_r($author); PHP: returns : Array ( [0] => robert crais at my websitethis is where it errors [1] => robert crais at my websitethis is where it errors )
That's happening because the regular expression is being too greedy. When this happens you need to be more precise with the regular expression and specify the characters that you expect to see between your parenthesis. Try this instead: $content = "read this great book by <b class=author>robert crais</b> at my website <b>this is where it errors</b>"; eregi("<b class=author>([A-Za-z ']+)</b>", $content, $author); print_r($author); PHP: If you expect to have other characters except the A-Z, a-z, space and apostrophe then you will need to add them to the list within the square brackets. Also note I've changed the single quotes in the first parameter of the eregi call to double quotes.
If you use preg_match rather than ereg then you can control the greediness of the regular expression, and so you won't have to specify every conceivable character which could fit between the tags.
This simple modification still uses the eregi function, but will match any character up to a '<', meaning you won't have to explicitly specify all the characters you wish to match: $content = "read this great book by <b class=author>robert crais</b> at my website <b>this is where it errors</b>"; eregi("<b class=author>([^<]+)</b>", $content, $author); print_r($author); PHP:
I think $author = preg_match("/<b class=author>(.*)<\/b>/U", $content); Code (markup): should do it but I can't test at the mo cheers John