From 79c601a7b3ee87943b92a5e6d77ce02480b49ffe Mon Sep 17 00:00:00 2001 From: Mark Evans Date: Sun, 6 Sep 2009 09:45:41 +0100 Subject: [PATCH] Replace ereg functions with preg functions for OSC-999 --- catalog/admin/backup.php | 6 +++--- catalog/admin/cache.php | 4 ++-- catalog/admin/includes/classes/phplot.php | 2 +- catalog/admin/includes/functions/general.php | 14 +++++++------- catalog/includes/classes/cc_validation.php | 2 +- catalog/includes/functions/general.php | 14 +++++++------- .../includes/modules/payment/sage_pay_direct.php | 2 +- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/catalog/admin/backup.php b/catalog/admin/backup.php index 43e81381d..20ee93287 100644 --- a/catalog/admin/backup.php +++ b/catalog/admin/backup.php @@ -63,7 +63,7 @@ $schema .= ',' . "\n"; } - $schema = ereg_replace(",\n$", '', $schema); + $schema = preg_replace("/,\n$/", '', $schema); // add the keys $index = array(); @@ -111,7 +111,7 @@ $schema .= 'NULL, '; } elseif (tep_not_null($rows[$i])) { $row = addslashes($rows[$i]); - $row = ereg_replace("\n#", "\n".'\#', $row); + $row = preg_replace("/\n#/", "\n".'\#', $row); $schema .= '\'' . $row . '\', '; } else { @@ -119,7 +119,7 @@ } } - $schema = ereg_replace(', $', '', $schema) . ');' . "\n"; + $schema = preg_replace('/, $/', '', $schema) . ');' . "\n"; fputs($fp, $schema); } } diff --git a/catalog/admin/cache.php b/catalog/admin/cache.php index a6205cb46..229e2bd68 100644 --- a/catalog/admin/cache.php +++ b/catalog/admin/cache.php @@ -80,7 +80,7 @@ } for ($i=0, $n=sizeof($cache_blocks); $i<$n; $i++) { - $cached_file = ereg_replace('-language', '-' . $language, $cache_blocks[$i]['file']); + $cached_file = preg_replace('/-language/', '-' . $language, $cache_blocks[$i]['file']); if (file_exists(DIR_FS_CACHE . $cached_file)) { $cache_mtime = strftime(DATE_TIME_FORMAT, filemtime(DIR_FS_CACHE . $cached_file)); @@ -89,7 +89,7 @@ $dir = dir(DIR_FS_CACHE); while ($cache_file = $dir->read()) { - $cached_file = ereg_replace('-language', '-' . $language, $cache_blocks[$i]['file']); + $cached_file = preg_replace('/-language/', '-' . $language, $cache_blocks[$i]['file']); if (ereg('^' . $cached_file, $cache_file)) { $cache_mtime = strftime(DATE_TIME_FORMAT, filemtime(DIR_FS_CACHE . $cache_file)); diff --git a/catalog/admin/includes/classes/phplot.php b/catalog/admin/includes/classes/phplot.php index 3e5e175f7..675489345 100644 --- a/catalog/admin/includes/classes/phplot.php +++ b/catalog/admin/includes/classes/phplot.php @@ -674,7 +674,7 @@ function DrawText($which_font,$which_angle,$which_xpos,$which_ypos,$which_color, if ($which_valign == 'top') { $which_ypos = $which_ypos - ImageFontHeight($which_font); } - $which_text = ereg_replace("\r","",$which_text); + $which_text = preg_replace("/\r/","",$which_text); $str = split("\n",$which_text); //multiple lines submitted by Remi Ricard $height = ImageFontHeight($which_font); $width = ImageFontWidth($which_font); diff --git a/catalog/admin/includes/functions/general.php b/catalog/admin/includes/functions/general.php index b20b26637..759027350 100644 --- a/catalog/admin/includes/functions/general.php +++ b/catalog/admin/includes/functions/general.php @@ -52,9 +52,9 @@ function tep_output_string_protected($string) { } function tep_sanitize_string($string) { - $string = ereg_replace(' +', ' ', $string); - - return preg_replace("/[<>]/", '_', $string); + $patterns = array ('/ +/','/[<>]/'); + $replace = array (' ', '_'); + return preg_replace($patterns, $replace, trim($string)); } function tep_customers_name($customers_id) { @@ -146,7 +146,7 @@ function tep_date_short($raw_date) { if (@date('Y', mktime($hour, $minute, $second, $month, $day, $year)) == $year) { return date(DATE_FORMAT, mktime($hour, $minute, $second, $month, $day, $year)); } else { - return ereg_replace('2037' . '$', $year, date(DATE_FORMAT, mktime($hour, $minute, $second, $month, $day, 2037))); + return preg_replace('/2037/' . '$', $year, date(DATE_FORMAT, mktime($hour, $minute, $second, $month, $day, 2037))); } } @@ -938,7 +938,7 @@ function tep_reset_cache_block($cache_block) { $cached_file = $cache_blocks[$i]['file']; $languages = tep_get_languages(); for ($j=0, $k=sizeof($languages); $j<$k; $j++) { - $cached_file_unlink = ereg_replace('-language', '-' . $languages[$j]['directory'], $cached_file); + $cached_file_unlink = preg_replace('/-language/', '-' . $languages[$j]['directory'], $cached_file); if (ereg('^' . $cached_file_unlink, $cache_file)) { @unlink(DIR_FS_CACHE . $cache_file); } @@ -950,7 +950,7 @@ function tep_reset_cache_block($cache_block) { $cached_file = $cache_blocks[$i]['file']; $languages = tep_get_languages(); for ($i=0, $n=sizeof($languages); $i<$n; $i++) { - $cached_file = ereg_replace('-language', '-' . $languages[$i]['directory'], $cached_file); + $cached_file = preg_replace('/-language/', '-' . $languages[$i]['directory'], $cached_file); @unlink(DIR_FS_CACHE . $cached_file); } } @@ -1276,7 +1276,7 @@ function tep_rand($min = null, $max = null) { // nl2br() prior PHP 4.2.0 did not convert linefeeds on all OSs (it only converted \n) function tep_convert_linefeeds($from, $to, $string) { if ((PHP_VERSION < "4.0.5") && is_array($from)) { - return ereg_replace('(' . implode('|', $from) . ')', $to, $string); + return preg_replace('/(' . implode('|', $from) . ')/', $to, $string); } else { return str_replace($from, $to, $string); } diff --git a/catalog/includes/classes/cc_validation.php b/catalog/includes/classes/cc_validation.php index 2ff760c46..63d807fb4 100644 --- a/catalog/includes/classes/cc_validation.php +++ b/catalog/includes/classes/cc_validation.php @@ -14,7 +14,7 @@ class cc_validation { var $cc_type, $cc_number, $cc_expiry_month, $cc_expiry_year; function validate($number, $expiry_m, $expiry_y) { - $this->cc_number = ereg_replace('[^0-9]', '', $number); + $this->cc_number = preg_replace('/[^0-9]/', '', $number); if (ereg('^4[0-9]{12}([0-9]{3})?$', $this->cc_number)) { $this->cc_type = 'Visa'; diff --git a/catalog/includes/functions/general.php b/catalog/includes/functions/general.php index 36cf16bbc..6987486a6 100644 --- a/catalog/includes/functions/general.php +++ b/catalog/includes/functions/general.php @@ -58,9 +58,9 @@ function tep_output_string_protected($string) { } function tep_sanitize_string($string) { - $string = ereg_replace(' +', ' ', trim($string)); - - return preg_replace("/[<>]/", '_', $string); + $patterns = array ('/ +/','/[<>]/'); + $replace = array (' ', '_'); + return preg_replace($patterns, $replace, trim($string)); } //// @@ -584,7 +584,7 @@ function tep_date_short($raw_date) { if (@date('Y', mktime($hour, $minute, $second, $month, $day, $year)) == $year) { return date(DATE_FORMAT, mktime($hour, $minute, $second, $month, $day, $year)); } else { - return ereg_replace('2037' . '$', $year, date(DATE_FORMAT, mktime($hour, $minute, $second, $month, $day, 2037))); + return preg_replace('/2037/' . '$', $year, date(DATE_FORMAT, mktime($hour, $minute, $second, $month, $day, 2037))); } } @@ -635,7 +635,7 @@ function tep_parse_search_string($search_str = '', &$objects) { */ // Add this word to the $tmpstring, starting the $tmpstring - $tmpstring = trim(ereg_replace('"', ' ', $pieces[$k])); + $tmpstring = trim(preg_replace('/"/', ' ', $pieces[$k])); // Check for one possible exception to the rule. That there is a single quoted word. if (substr($pieces[$k], -1 ) == '"') { @@ -685,7 +685,7 @@ function tep_parse_search_string($search_str = '', &$objects) { $piece onto the tail of the string, push the $tmpstring onto the $haves, kill the $tmpstring, turn the $flag "off", and return. */ - $tmpstring .= ' ' . trim(ereg_replace('"', ' ', $pieces[$k])); + $tmpstring .= ' ' . trim(preg_replace('/"/', ' ', $pieces[$k])); // Push the $tmpstring onto the array of stuff to search for $objects[] = trim($tmpstring); @@ -1300,7 +1300,7 @@ function tep_count_customer_address_book_entries($id = '', $check_session = true // nl2br() prior PHP 4.2.0 did not convert linefeeds on all OSs (it only converted \n) function tep_convert_linefeeds($from, $to, $string) { if ((PHP_VERSION < "4.0.5") && is_array($from)) { - return ereg_replace('(' . implode('|', $from) . ')', $to, $string); + return preg_replace('/(' . implode('|', $from) . ')/', $to, $string); } else { return str_replace($from, $to, $string); } diff --git a/catalog/includes/modules/payment/sage_pay_direct.php b/catalog/includes/modules/payment/sage_pay_direct.php index 1709f281b..4ec64b2d9 100644 --- a/catalog/includes/modules/payment/sage_pay_direct.php +++ b/catalog/includes/modules/payment/sage_pay_direct.php @@ -157,7 +157,7 @@ function before_process() { } else { $cc_type = substr($HTTP_POST_VARS['cc_type'], 0, 15); $cc_owner = substr($HTTP_POST_VARS['cc_owner'], 0, 50); - $cc_number = substr(ereg_replace('[^0-9]', '', $HTTP_POST_VARS['cc_number_nh-dns']), 0, 20); + $cc_number = substr(preg_replace('/[^0-9]/', '', $HTTP_POST_VARS['cc_number_nh-dns']), 0, 20); $cc_start = null; $cc_expires = null; $cc_issue = null;