Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP - Function eregi() is deprecated error message.

Posted on 2012-03-13
3
Medium Priority
?
710 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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 111

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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

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…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

722 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