Deprecated Error: Function ereg()

Asked

Viewed 2,943 times

5

In the script that I installed gave this error:

Deprecated: Function ereg() is deprecated in /home/u844214382/public_html/funciones.php on line 98 Deprecated:

Code in row 98:

if (ereg("^[a-zA-Z0-9\-_]{3,20}$", $mensaje)) {

There are also other calls to ereg in the same filing cabinet.

  • Would be a Warning, right? You mean in the version of PHP you are using (what is it?), the ereg is considered obsolete. You need to use another function, or have php mute warnings.

  • How can I do that?

  • So the ideal would be to use preg_match instead of the ereg.

  • Already used more didn’t work, Could put in the Code? why I don’t know much of php.

2 answers

3

ereg_* was marked as obsolete (deprecated) in PHP 5.3. To fix this error, simply switch to preg_match. For example:

ereg("^[a-zA-Z0-9\-_]{3,20}$", $nombre_usuario)

Exchange for:

 if (preg_match("/^[a-zA-Z0-9\-_]{3,20}$/", $nombre_usuario)){
      ----------^                       ^----------- 
 inicio do delimitador                   fim do delimitador

To fix your code it is necessary to change the ereg in the functions:

  1. Validamail()
  2. Shout()
  3. uc()

Basically what changes is that you forced to put your regex among some delemitador, in case it was /. Another point is that ereg is based on the regex of Unix equator preg_* is in the Perl (see PCRE modifiers).

  • Gave this Warning: preg_match(): no ending delimiter '^'

  • It seems that the delimiting is in the wrong place.

  • I put so if (preg_match("/ [a-za-Z0-9-_]{3,20}$/", $nombre_usuario)); {

  • Online if, will not ;. Remove the ; before the key. $nombre_usuario)); {

  • Hasn’t solved.

  • I changed the answer, I was missing a \.

  • Where do I put the ? I’m sorry I’m asking too many questions is because I’m very Noob, If you can tell me the complete code without error.

  • 3

    @user7329 Don’t take this the wrong way, but try to understand the problems that are happening. As soon as you solve the problem of this line, others will appear (there are several ereg in the code you posted). The business of this site is not to solve each one’s particular problem, but to create a repository of questions and answers that can be useful to multiple people with similar problems. The more this becomes a dialogue to resolve the details of your code, the less suitable the site will be (shortly the system will suggest that you continue the discussion in chat).

  • I know more guy I’m trying to solve this mistake since morning and I can’t!

  • Still gives the same http://homebux.com.br error/

  • What is line 98?

  • Yeah, Warning: preg_match(): No ending delimiter ' ' found in /home/u844214382/public_html/funciones.php on line 98 The Field admin is not Valid

  • Put the code line 98, that’s the error message.

  • if (preg_match("/ [a-za-Z0-9-_]{3,20}$/", $Mensaje)) {

  • I still can’t fix it!

Show 10 more comments

2

Your php version is up to date and letting you know that ereg no longer works.

You can substitute for preg_match() which is an alternative.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.