Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function ereg() is deprecated

Tags:

regex

php

I have started to learn PHP. So installed WAMP server on my windows 7 machine. I am trying the following PHP code :

<?php
$phrase = "I love PHP";
if (ereg("PHP", $phrase)) {
  echo "The expression matches";
}
?>

When tried this in my mozilla, I got the output :

Deprecated: Function ereg() is deprecated in C:\wamp\www\learnphp\common.php on line 3
The expression matches

I think the code is correct. I can't understand the error. Can anybody explain me what this "Deprecated" means here? and how to solve this error?

My php version is 5.3.0. can it be version problem?

EDIT : I googled it and found something about include\file.inc file in www folder. I don't have include directory in my www folder.

like image 880
narayanpatra Avatar asked Nov 28 '10 15:11

narayanpatra


2 Answers

"Deprecated" means that PHP 5.3.0 no longer supports that function.

You should treat ereg() as not existing anymore.

The function does still exist, but only to support existing applications where it's been used.

When writing new code, never use a deprecated function.

Instead, consider the preg_match function.

like image 146
VoteyDisciple Avatar answered Nov 09 '22 00:11

VoteyDisciple


Deprecated means this function will eventually be removed from PHP in a future version. You should no longer rely on it in your code and instead use the suggested alternative.

In case of PHP's ereg, heed the notice in the PHP Manual:

As of PHP 5.3.0, the regex extension is deprecated in favor of the PCRE extension. Calling this function will issue an E_DEPRECATED notice. See the list of differences for help on converting to PCRE.

Also see the description of E_DEPRECATED in the PHP Manual.
For all deprecated features in PHP5.3, see Deprecated features in PHP 5.3.x.
For more general information see the Wikipedia article on Deprecation in Software

like image 6
Gordon Avatar answered Nov 09 '22 00:11

Gordon