Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

PHP Ereg Warning

Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Watch

sastro

Account Closed
Impact
1
Here is the code
PHP:
if(ereg('\'|+',$str)){
.
.
.
}

I need to find ' or + in the str but got warning :

[15-May-2009 15:57:26] PHP Warning: ereg() [<a href='function.ereg'>function.ereg</a>]: REG_BADRPT in D:\http\index.php on line 118

Please help me.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
I'd suggest trying:

PHP:
if (ereg("('|\+)", $str))
{
	//
}
 
0
•••
Try this:

PHP:
if(eregi("'", $str) || eregi("+", $str)){

}
 
0
•••
Try this:

PHP:
if(eregi("'", $str) || eregi("+", $str)){

}

waste of resources tbh, Eric has the best option if regular expressions are really required. No point using 2 regular expressions though.

An alternative is

PHP:
if(strpbrk($str, '\'+'))
{
  echo 'do whatever';
}

This negates the need for a regular expression.
 
0
•••
Thx for replied,

Here is the result

HTML:
strpbrk($str, '\'+') found in 4.3869018554688E-5 sec.
ereg("('|\+)", $str) found in 2.288818359375E-5 sec.
ereg("['|\+]", $str) found in 1.8119812011719E-5 sec.
eregi("'", $str) || eregi("+", $str)) found in 4.3153762817383E-5 sec.

So i think ereg("['|\+]", $str) is faster.
 
0
•••
Hmm very surprised that strpbrk took so long to be honest would ahve expected it to be more efficient.

You may find that the following is faster:-

PHP:
ereg('[\'|\+]', $str)

It should be faster as it is not having to check to see if there are any variables in the regular expression.
 
0
•••
Code:
strpbrk($str, '\'+') found in 4.2915344238281E-5 sec.
ereg("('|\+)", $str) found in 2.3841857910156E-5 sec.
ereg("['|\+]", $str) found in 1.8119812011719E-5 sec.
ereg("'", $str) || eregi("+", $str)) found in 1.7881393432617E-5 sec.
ereg('[\'|\+]', $str) found in 1.5974044799805E-5 sec.

Yupe you're right, ereg('[\'|\+]', $str) is faster...
thx
 
0
•••
A single regular expression is always faster than two (since it's only one function call) but a regular expression is always faster than a non-regex function call with two arguments. (in PHP)
 
0
•••
Code:
ereg('[\'|\+]', $str)

does not do what you want. It also matches the vertical bar ("|") character. You want to use:

Code:
ereg('[\'\+]', $str)

Also, the tests you have performed are data dependant.

A single regular expression is always faster than two (since it's only one function call)

I think things are perhaps a little more complicated that that. You should find that:

Code:
(ereg("'", $str) || eregi("+", $str))

is faster at matching strings containing a single quote (and slower if they do not). If you expect your input to contain single quotes 99.99% of the time, it will be faster on average than using the following:

Code:
ereg('[\'\+]', $str)

Also, strpos seems to be faster than ereg when searching for simple strings.
 
0
•••
Code:
ereg('[\'|\+]', $str)

does not do what you want. It also matches the vertical bar ("|") character. You want to use:

Code:
ereg('[\'\+]', $str)

quite right well spotted
 
0
•••
get out of the habit of using ereg, it is to be removed from php6, thus your software will break upon upgrade. I have heard that it may happen sooner, though.
 
0
•••
To be specific, ereg has been removed from the PHP6 core, but is still available as an optional extension.

I would expect most hosting providers will enable it for a long time to come, so I don't think there is a need to change working scripts for a while.
 
0
•••
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

New in Parking: updated way to act on many domains or inquiries at once
Your domain list and inquiry list now have a bar above and below the list. Check the items you want, then choose an action in the bar...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back