Another newbie question: PHP Deprecated: Function ereg()..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
insodoneva
Forum Newbie
Posts: 4
Joined: Mon Jun 07, 2010 7:50 am

Another newbie question: PHP Deprecated: Function ereg()..

Post by insodoneva »

I just found this error in my log:
"PHP Deprecated: Function ereg() is deprecated in …line 61."
And here is the line:

Code: Select all

$enable_contact = $params->get( 'enable_contact' );
Can anyone please help me fix this?
The only ereg I can see in the document is however on line 121:

Code: Select all

$br = ( !empty( $_SERVER['USER_AGENT'] ) ) ? strtolower( $_SERVER['USER_AGENT'] ) : strtolower( $_SERVER['HTTP_USER_AGENT'] ) ;
	if(ereg("msie", $br))
	{
		$document->addStyleSheet( 'modules/mod_login/assets/css/colorbox-ie.css' );
	}
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Another newbie question: PHP Deprecated: Function ereg(

Post by Jonah Bron »

Get rid of all eregi()s. Use preg_match(), or, if you're not using regex, compare strpos() to false (use triple equal comparison, ===).
insodoneva
Forum Newbie
Posts: 4
Joined: Mon Jun 07, 2010 7:50 am

Re: Another newbie question: PHP Deprecated: Function ereg(

Post by insodoneva »

Can you please help me with that. I really cannot do the syntax.
Here is the lines before the problematic c line 61:

Code: Select all

require_once ( dirname(__FILE__) . DS . 'helper.php' );
$params->def( 'greeting', 1 );
$type 	= modLoginHelper::getType();
$return	= modLoginHelper::getReturnURL( $params, $type );
$enable_login = $params->get( 'enable_login' );
$enable_register = $params->get( 'enable_register' );
$enable_contact = $params->get( 'enable_contact' );

And here is the only ereg I can find in the entire page:

Code: Select all

$document->addScript( 'modules/mod_login/assets/js/jquery.colorbox.js' );

		$document->addScript( 'modules/mod_login/assets/js/div.js' );

	$document->addStyleSheet( 'modules/mod_login/assets/css/colorbox.css' );

	$br = ( !empty( $_SERVER['USER_AGENT'] ) ) ? strtolower( $_SERVER['USER_AGENT'] ) : strtolower( $_SERVER['HTTP_USER_AGENT'] ) ;

	if(ereg("msie", $br))

	{

		$document->addStyleSheet( 'modules/mod_login/assets/css/colorbox-ie.css' );
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: Another newbie question: PHP Deprecated: Function ereg(

Post by markusn00b »

You have no need for regular expressions in this example. Use strpos(), as suggested, instead.

Code: Select all

if (strpos($br, 'msie') !== FALSE) {

}
Post Reply