Solved

PHP - Function eregi() is deprecated error message.

Posted on 2012-03-13
3
699 Views
Last Modified: 2012-06-27
Hi,
I am receiving the following error message.

Deprecated: Function eregi() is deprecated in /home/mywebsit/public_html/includes/functions.php on line 262

How should I recode the code below to correct the error?


$GP_uploadAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
  if (!eregi("GP_upload=true", $HTTP_SERVER_VARS['QUERY_STRING'])) {
            $GP_uploadAction .= "?".$HTTP_SERVER_VARS['QUERY_STRING']."&GP_upload=true";
      } else {
            $GP_uploadAction .= "?".$HTTP_SERVER_VARS['QUERY_STRING'];
      }
} else {
  $GP_uploadAction .= "?"."GP_upload=true";
}
0
Comment
Question by:sabecs
3 Comments
 
LVL 15

Expert Comment

by:StingRaY
ID: 37713453
$GP_uploadAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
  if (preg_match("/GP_upload=true/", $HTTP_SERVER_VARS['QUERY_STRING']) == 0) {
            $GP_uploadAction .= "?".$HTTP_SERVER_VARS['QUERY_STRING']."&GP_upload=true";
      } else {
            $GP_uploadAction .= "?".$HTTP_SERVER_VARS['QUERY_STRING'];
      }
} else {
  $GP_uploadAction .= "?"."GP_upload=true";
}

Open in new window

0
 
LVL 48

Accepted Solution

by:
hernst42 earned 500 total points
ID: 37713461
you can use stripos as no wildcard is in your regexp and thus no regular expression needed. Also replace the HTTP- long array as they are gone wiht php 5.4. THis code works without warning on php 5.4

$GP_uploadAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  if (stripos("GP_upload=true", $_SERVER['QUERY_STRING']) === false) {
            $GP_uploadAction .= "?".$_SERVER['QUERY_STRING']."&GP_upload=true";
      } else {
            $GP_uploadAction .= "?".$_SERVER['QUERY_STRING'];
      }
} else {
  $GP_uploadAction .= "?"."GP_upload=true";
}

Open in new window

0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 37714071
For PHP developers, the PHP.net web site is an invaluable resource.  If you are upgrading to PHP 5.4, you really need to read this:
http://php.net/migration54

On that page you will also find a line with the links for the other recent upgrade paths.  It says something like this:
See also the migration guides for PHP versions 5.0.x, 5.1.x, 5.2.x and 5.3.x.

The migration guides explain what is deprecated and what is removed, as well as what is added in each new release of PHP.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How do uses indexes to maximize MySQL Searches 14 55
Cpanel file manager 8 42
hbo knew my windows software 4 63
what do I need to host my own web sites? 13 52
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question