Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Function ereg_replace() is deprecated


ianric

Recommended Posts

Hi

 

Just testing my site locally with Wampserver and PHP 5.3 and I'm getting the following error when viewing a product, product_info.php

 

Deprecated: Function ereg_replace() is deprecated in C:\wamp\www\includes\functions\general.php on line 61

 

It's this function

 

  function tep_sanitize_string($string) {
$string = ereg_replace(' +', ' ', trim($string));

return preg_replace("/[<>]/", '_', $string);
 }

 

I Searched and managed to clear a similar error in the classes\language.php. That solution changed ereg to preg_match

 

I'm also getting the same error displayed on the index.php. Deprecated: Function ereg() is deprecated in C:\wamp\www\index.php on line 196, another ereg statement. It happens when I filter the product listing via the manufacturers drop down, shows results pages 1 to 5 navigation just below.

 

 

// We are asked to show only specific catgeory
	$listing_sql = "select " . $select_column_list . " p.products_date_added, p.products_id, p.manufacturers_id, m.manufacturers_name, p.products_price, p.products_media, p.products_label, p.products_catno, p.products_model, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_MANUFACTURERS . " m, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_status = '1' and p.manufacturers_id = m.manufacturers_id and m.manufacturers_id = '" . (int)$HTTP_GET_VARS['filter_id'] . "' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$current_category_id . "'";
  } else {
// We show them all
	$listing_sql = "select " . $select_column_list . " p.products_date_added, p.products_id, p.manufacturers_id, m.manufacturers_name, p.products_price, p.products_media, p.products_label, p.products_catno, p.products_model, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_status = '1' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$current_category_id . "'";
  }
}

This is line 196	if ( (!isset($HTTP_GET_VARS['sort'])) || (!ereg('^[1-8][ad]$', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'], 0, 1) > sizeof

($column_list)) ) {
  for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
	if ($column_list[$i] == 'PRODUCT_LIST_NAME') {
	  $HTTP_GET_VARS['sort'] = $i+1 . 'a';
	  $listing_sql .= " order by pd.products_name";
	  break;
	}
  }
} else... {

 

Please could someone hold my hand for a while. Any help will be much appreciated

 

Cheers

 

Ian

Link to comment
Share on other sites

  • Replies 137
  • Created
  • Last Reply

Try changing

  function tep_sanitize_string($string) {
$string = ereg_replace(' +', ' ', trim($string));

return preg_replace("/[<>]/", '_', $string);
 }

to

  function tep_sanitize_string($string) {
$string = preg_replace('{ +}', ' ', trim($string));

return preg_replace("/[<>]/", '_', $string);
 }

and see if that does what you want.

Always back up before making changes.

Link to comment
Share on other sites

Try changing
  function tep_sanitize_string($string) {
$string = ereg_replace(' +', ' ', trim($string));

return preg_replace("/[<>]/", '_', $string);
 }

to

  function tep_sanitize_string($string) {
$string = preg_replace('{ +}', ' ', trim($string));

return preg_replace("/[<>]/", '_', $string);
 }

and see if that does what you want.

 

Hi Ecartz

 

Thanks for that. It did the trick

 

Two down, one to go. Just need to do a bit of reading and try to figure out the same error in index.php

 

Just one more thing, is changing the ereg to preg_replace backwards compatible?

 

Thanks again

 

Ian

Link to comment
Share on other sites

Just one more thing, is changing the ereg to preg_replace backwards compatible?
Yes. The preg_replace function has been standard in PHP since 4.2 (and existed earlier than that). You can read more about it at the documentation for PCRE on the php.net site.

 

In terms of osCommerce, the version that I suggested should be exactly equivalent to the original with ereg. The syntax is different but the functionality should be identical.

 

Some other ereg_replace calls that you might find:

ereg_replace('2037' . '$', $year, date(DATE_FORMAT, mktime($hour, $minute, $second, $month, $day, 2037)))
ereg_replace('"', ' ', $pieces[$k])
ereg_replace('(' . implode('|', $from) . ')', $to, $string)
ereg_replace('[^0-9]', '', $number)
ereg_replace('-language', '-' . $languages[$j]['directory'], $cached_file)
ereg_replace('(' . implode('|', $from) . ')', $to, $string)
ereg_replace("\r","",$which_text)
ereg_replace('-language', '-' . $language, $cache_blocks[$i]['file'])
ereg_replace(",\n$", '', $schema)
ereg_replace("\n#", "\n".'\#', $row)
ereg_replace(', $', '', $schema)

would become

preg_replace('{2037\z}', $year, date(DATE_FORMAT, mktime($hour, $minute, $second, $month, $day, 2037)))
str_replace('"', ' ', $pieces[$k])
preg_replace('{(' . implode('|', $from) . ')}', $to, $string)
preg_replace('{\D}', '', $number)
str_replace('-language', '-' . $languages[$j]['directory'], $cached_file)
str_replace("\r","",$which_text)
str_replace('-language', '-' . $language, $cache_blocks[$i]['file'])
preg_replace("{,\n\z}", '', $schema)
preg_replace("{\n#}", "\n".'\#', $row)
preg_replace('{, \z}', '', $schema)

Warning: I haven't tested any of these.

Always back up before making changes.

Link to comment
Share on other sites

These 3 are also deprecated from PHP5.3

 

ereg

 

eregi

 

eregi_replace

Link to comment
Share on other sites

  • 2 weeks later...
These 3 are also deprecated from PHP5.3

 

ereg

 

eregi

 

eregi_replace

 

to what has the EREG has to be changed. Damned, this XAMPP upgrade (PHP upgrade actually to 5.3) gives me a hell of a lot of errors (and work)

Link to comment
Share on other sites

The list of effected functions is bigger than that, its due to the regex extension being deprecated

 

ereg_ replace

ereg

eregi_ replace

eregi

split

spliti

sql_ regcase

Sam

 

Remember, What you think I ment may not be what I thought I ment when I said it.

 

Contributions:

 

Auto Backup your Database, Easy way

 

Multi Images with Fancy Pop-ups, Easy way

 

Products in columns with multi buy etc etc

 

Disable any Category or Product, Easy way

 

Secure & Improve your account pages et al.

Link to comment
Share on other sites

Replacing the deprecated SPLIT function

 

A question came up asking how to replace the split used in the tep_parse_search_string function (about 594 of general.php)

 

existing line:

 

$pieces = split('[[:space:]]+', $search_str);

 

replace with:

 

$pieces = preg_split("/[\s,]+/", $search_str);

 

This new code has the added advantage that it splits on commas too, which would cause failure on old code.

Sam

 

Remember, What you think I ment may not be what I thought I ment when I said it.

 

Contributions:

 

Auto Backup your Database, Easy way

 

Multi Images with Fancy Pop-ups, Easy way

 

Products in columns with multi buy etc etc

 

Disable any Category or Product, Easy way

 

Secure & Improve your account pages et al.

Link to comment
Share on other sites

to what has the EREG has to be changed.
ereg would go to preg_match or strstr or strpos, e.g.
	  if (ereg('->', $use_function)) {

would become

	  if (preg_match('{->}', $use_function)) {

or

	  if (strstr('->', $use_function) !== false) {

or

	  if (strpos('->', $use_function) !== false) {

For performance reasons, strpos would be preferred in that example. However, it won't always work. I can't find any examples of eregi or eregi_replace in the osCommerce code base, but you can add an i to the PCRE pattern to make it case insensitive, e.g. '{a}i' would match both a and A.

Always back up before making changes.

Link to comment
Share on other sites

  • 3 weeks later...

I'm hoping this may be the official ereg answer post - because it's currently doing my head in :huh:

 

I only have php5.3 on my computer and which I use for adding (add-ons etc) and testing my store on.

 

Anyway I've been updating ereg and eregi as they occur - well at some time or other we are going to get php6 on-line and we store owners need to be ready v3 may or may not be ready and even if it is it may or may not have the add-ons I want or accept the tweeks I require.

 

currently I've hit a problem where I can't load to the cart (only on my computer) I'm using the same file as my live shop (with the exception of both configure.php files)

 

The error I get on clicking add to cart is: Fatal error: Call to undefined function preg() in /Applications/XAMPP/xamppfiles/htdocs/includes/functions/general.php on line 1094 which is:

		if (preg('/^[0-9]$/', $char)) $rand_value .= $char;
  }

and was:

		if (ereg('^[0-9]$', $char)) $rand_value .= $char;
  }

which gave this as an error:

 

Deprecated: Function ereg() is deprecated in /Applications/XAMPP/xamppfiles/htdocs/includes/functions/general.php on line 1094

 

Deprecated: Function ereg() is deprecated in /Applications/XAMPP/xamppfiles/htdocs/includes/functions/general.php on line 1094

 

Deprecated: Function ereg() is deprecated in /Applications/XAMPP/xamppfiles/htdocs/includes/functions/general.php on line 1094

 

Deprecated: Function ereg() is deprecated in /Applications/XAMPP/xamppfiles/htdocs/includes/functions/general.php on line 1094

 

Deprecated: Function ereg() is deprecated in /Applications/XAMPP/xamppfiles/htdocs/includes/functions/general.php on line 1094

 

Warning: Cannot modify header information - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/includes/functions/general.php:1094) in /Applications/XAMPP/xamppfiles/htdocs/includes/functions/general.php on line 33

 

line 33 is:

	header('Location: ' . $url);

 

My question is (apart from help!) are we able to change the ereg as they crop up or do we have to find them all and change them at once?

My store is currently running Phoenix 1.0.3.0

I'm currently working on 1.0.7.2 and hope to get it live before 1.0.8.0 arrives (maybe 🙄 )

I used to have a list of add-ons here but I've found that with the ones that supporters of Phoenix get any other add-ons are not really neccessary

Link to comment
Share on other sites

As Matt pointed out, you would replace ereg with preg_match, preg does not exist!!

 

so

if (ereg('^[0-9]$', $char)) $rand_value .= $char;

becomes

if (preg_match('^[0-9]$', $char)) $rand_value .= $char;

 

Also as has been pointed out elsewhere, a work around (till v6 at least) is:

 

In includes/application_top.php and admin/includes/application_top.php

 

find:

 

 //set the level of error reporting
 error_reporting(E_ALL & ~E_NOTICE);

 

replace with:

 

//set the level of error reporting
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);

Sam

 

Remember, What you think I ment may not be what I thought I ment when I said it.

 

Contributions:

 

Auto Backup your Database, Easy way

 

Multi Images with Fancy Pop-ups, Easy way

 

Products in columns with multi buy etc etc

 

Disable any Category or Product, Easy way

 

Secure & Improve your account pages et al.

Link to comment
Share on other sites

Doh! :blush:

 

works now

 

Thank you spooks

 

 

The work around is ok at the moment but is going to pretty useless when php6 comes along which is why I've decided to update them

My store is currently running Phoenix 1.0.3.0

I'm currently working on 1.0.7.2 and hope to get it live before 1.0.8.0 arrives (maybe 🙄 )

I used to have a list of add-ons here but I've found that with the ones that supporters of Phoenix get any other add-ons are not really neccessary

Link to comment
Share on other sites

hi

 

i am new with OS Commerce

 

i have got this problem

 

on the top of the page there are

Deprecated: Function eregi() is deprecated in C:\Program Files\EasyPHP5.3.0\www\catalog\includes\classes\language.php on line 87

 

What does it mean and How can i solve this problem

Thanks.

Link to comment
Share on other sites

Hi simas12 ,

 

As you are new to osCommerce your best bet may well be to do the fix Sam has describe here especially if you need to get a store running - it will last you until your server updates to php6 (mine is only running php 5.2.9 at the moment)

 

Also as has been pointed out elsewhere, a work around (till v6 at least) is:

 

In includes/application_top.php and admin/includes/application_top.php

 

find:

 

 //set the level of error reporting
 error_reporting(E_ALL & ~E_NOTICE);

 

replace with:

 

//set the level of error reporting
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);

My store is currently running Phoenix 1.0.3.0

I'm currently working on 1.0.7.2 and hope to get it live before 1.0.8.0 arrives (maybe 🙄 )

I used to have a list of add-ons here but I've found that with the ones that supporters of Phoenix get any other add-ons are not really neccessary

Link to comment
Share on other sites

The unix diff from admin/includes/classes/phplot.php:

677,678c677,678
<					   $which_text = ereg_replace("\r","",$which_text);
<					   $str = split("\n",$which_text); //multiple lines submitted by Remi Ricard
---
>					   $which_text = str_replace("\r", '', $which_text);
>					   $str = explode("\n",$which_text); //multiple lines submitted by Remi Ricard
782c782
<			   if (eregi($asked, $accepted)) {
---
> 		 if ( preg_match('{' . $asked . '}i', $accepted) ) {
939c939
<			   $str = split("\n",$this->title_txt); 
---
>			   $str = explode("\n",$this->title_txt);

Note that three of these are examples of times when it is more appropriate not to use a regular expression function at all. For those who are not familiar with unix diff, the lines that start with < are the old lines and the lines that start with > are the replacements. The numbers are line numbers for the lines that follow, e.g. lines 677 and 678 in the original file are replaced by lines 677 and 678 in the new file. The greater than signs should not be pasted into the file.

Always back up before making changes.

Link to comment
Share on other sites

  • 1 month later...

Hi

 

Thanks to everyone helping me out on this. At first it was very daunting but after reading the manual and Google, it's quite easy. I've decided to add to this thread so that it's all in one place for the future.

 

One edit that has me stumped is this code in admin/server_info.php

 

<?php
   ob_start();
   phpinfo();
   $phpinfo = ob_get_contents();
   ob_end_clean();

   $phpinfo = str_replace('border: 1px', '', $phpinfo);

*** This ereg statement here ***
   ereg('<body>(.*)</body>', $phpinfo, $regs);


   echo '<table border="1" cellpadding="3" width="600" style="border: 0px; border-color: #000000;">' .
        '  <tr><td><a href="http://www.oscommerce.com"><img border="0" src="images/oscommerce.png" title="' . PROJECT_VERSION . '" /></a><h1 class="p"> ' . PROJECT_VERSION . '</h1></td>' .
        '  </tr>' .
        '</table>';
   echo $regs[1];
 } else {
   phpinfo();
 }
?>

 

I can't figure this one out. Even examples I found on the net don't seem to work. If I replace with

 

preg_match('/<body>(.*)</body>/', $phpinfo, $regs);

 

I get "Warning: preg_match() [function.preg-match]: Unknown modifier 'b' in C:\xampp\Htdocs\admin\server_info.php on line 113"

 

I've tried | as a different modifer, (Google)?? Escaping the \/body cures the error messages but only the osc.png is displayed, not the whole info pages.

 

The other one is in admin/banner_manager.php

 

I've updated the file to PHP 5.3 but I get

 

"Warning: imagecolorexact(): 66 is not a valid Image resource in C:\xampp\Htdocs\admin\includes\classes\phplot.php on line 1305". The error is repeated 16 times with same and different line numbers. This is the function on line 1305

 

function SetIndexColor($which_color) { //Color is passed in as anything
 		list ($r, $g, $B) = $this->SetRgbColor($which_color);  //Translate to RGB
	$index = ImageColorExact($this->img, $r, $g, $B);
	if ($index == -1) {
  			//return ImageColorAllocate($this->img, $r, $g, $B);
  			//return ImageColorClosest($this->img, $r, $g, $B);
  			return ImageColorResolve($this->img, $r, $g, $B); //requires PHP 3.0.2 and later
		} else {
  			return $index;
 		}
}

 

I *think* these are my last fixes so any help would be appreciated.

 

Many thanks again

 

Ian

Link to comment
Share on other sites

preg_match('/<body>(.*)</body>/', $phpinfo, $regs);

Try
preg_match('{<body>(.*)</body>}xsmi', $phpinfo, $regs);

You may only need s or m, but it worked in my test with all of them and it's a Perl Best Practice to use xsm (along with the {} as the regex delimiters). The i covers a possible issue where you might have <BODY> rather than <body>.

 

In regards to your banner manager issue, are you using the same code changes that I proposed or different ones? If different ones, could you try the ones that I posted? If that doesn't work, please post what you are trying.

 

Incidentally, Mark Evans was working on a version of 2.2 without the deprecated functions. You might be able to get that on github.

Always back up before making changes.

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...

As Matt pointed out, you would replace ereg with preg_match, preg does not exist!!

 

so

if (ereg('^[0-9]$', $char)) $rand_value .= $char;

becomes

if (preg_match('^[0-9]$', $char)) $rand_value .= $char;

 

Hi Sam

 

Shouldn't

if (preg_match('^[0-9]$', $char)) $rand_value .= $char;

 

be

if (preg_match('^[0-9]$^', $char)) $rand_value .= $char;

 

As i got an error missing delimiter ^

 

Steve

Link to comment
Share on other sites

hi

 

i am new with OS Commerce

 

i have got this problem

 

on the top of the page there are

Deprecated: Function eregi() is deprecated in C:\Program Files\EasyPHP5.3.0\www\catalog\includes\classes\language.php on line 87

 

What does it mean and How can i solve this problem

Thanks.

find that line

if (eregi('^(' . $value . ')(;q=[0-9]\\.[0-9])?$', $this->browser_languages[$i]) && isset($this->catalog_languages[$key])) {

 

replace it with

if (preg_match('/^(' . $value . ')(;q=[0-9]\.[0-9])?$/i', $this->browser_languages[$i]) && isset($this->catalog_languages[$key])) {

 

Steve

Link to comment
Share on other sites

  • 3 weeks later...

Hello,

 

I am new at this forum and have only recently installed OSCommerce. I have followed all installation steps carefully and succeeded in the installation, which is running on localhost on my XP machine.

I use the following versions:

OSCommerce 2.2-RC2

Apache 2.2.13 (Win32)

PHP 5.3.0

MySQL 5.1.37

 

I also ran into the problems with ereg / eregi etc and used the solution offered here to (for the moment) get rid of the error messages by replacing

error_reporting(E_ALL & ~E_NOTICE); in: includes/application_top.php and admin/includes/application_top.php

by : error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);

This works :D (well, it gets rid of the error messages).

 

I have set up the store using the administrator section and I can create a customer account in the shop. However when I try to login using the customer login and password it will just return to the login page and will not login the customer. Nor can I add any product to the shopping cart! Anybody any idea what I overlooked here? Has it got something to do with the imcompatibility described here (ereg / eregi)? I can see in the database that the account I created actually exists, so that is not the problem. Suggestions/help welcome! Thanks! :)

Link to comment
Share on other sites

However when I try to login using the customer login and password it will just return to the login page and will not login the customer. Nor can I add any product to the shopping cart! Anybody any idea what I overlooked here?

Try using 127.0.0.1 instead of localhost in your configure.php files.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...