FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » regex help
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: regex help [message #176241 is a reply to message #176237] Fri, 09 December 2011 13:16 Go to previous messageGo to previous message
Kim Andr Aker is currently offline  Kim Andr Aker
Messages: 17
Registered: September 2010
Karma:
Junior Member
På Fri, 09 Dec 2011 04:51:56 +0100, skrev Jerry Stuckle
<jstucklex(at)attglobal(dot)net>:

> OK, guys, I'll be the first to admit my regex knowledge is more than
> limited. And I've never used ereg().
>
> So, I need to convert the following ereg() call in some code I'm
> modifying to a preg() call. Can someone please tell me what the ereg()
> does and the equivalent preg()?
>
> if (ereg("(error</b>:)(.+)(<br)", $buffer, $regs))

ereg() will return the length of the first matched string, if any, or
FALSE if nothing was found. The "if" surrounding it basically is triggered
if the return value is non-false.
On the other hand,preg_match() will return the number of matches (0 or 1,
since it stops after the first match).

Even though they're pretty close, preg_* follows Perl-based regexes, and
as you pointed out earlier, ereg* uses POSIX regexes. Then again, the
regex in your code line above is simple enough to be converted almost
verbatim to preg_* functions, with the addition of a separator and
escaping said separator inside the regex (the forward slash being the most
commonly used):

if (preg_match("/(error<\/b>\:)(.+)(<br)/", $buffer, $regs) == 1)

--
Kim André Akerø
- kimandre(at)NOSPAMbetadome(dot)com
(remove NOSPAM to contact me directly)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: <beg> ADODB PHP Extension Help </beg>
Next Topic: Edit a record?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 13 01:14:21 GMT 2024

Total time taken to generate the page: 0.05184 seconds