Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP - Function eregi() is deprecated error message.

Posted on 2012-03-13
3
Medium Priority
?
715 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

877 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