Ereg_replace trong PHP

My web host recommend an upgrade to PHP 7 but my Wordpress theme is using a deprecated ereg expression that is breaking the comments section. Here's the offending code

function the_commenter_link[] {
    $commenter = get_comment_author_link[];
    if [ ereg[ ']* class=[^>]+>', $commenter ] ] {$commenter = ereg_replace[ '[]* class=[\'"]?]', '\\1url ' , $commenter ];
    } else { $commenter = ereg_replace[ '[]+>', $commenter ] ] {$commenter = preg_replace[ '[]* class=[\'"]?]', '\\1url ' , $commenter ];
    } else { $commenter = preg_replace[ '[ sizeof

[$column_list]] ] {
  for [$i=0, $n=sizeof[$column_list]; $i sizeof

[$column_list]] ] {
  for [$i=0, $n=sizeof[$column_list]; $i 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

Share this post

Link to postShare on other sites

ianric    1

ianric    1

  • Các thành viên
  • 1
  • 373 posts
  • Real Name. Ian Richardson
  • Giới tính. một giả định
  • Location. Manchester, UK

Posted October 7, 2009

Xin chào

 

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

 

  function tep_sanitize_string[$string] {
$string = ereg_replace[' +', ' ', trim[$string]];

return preg_replace["/[]/", '_', $string];
 }
4

 

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

 

  function tep_sanitize_string[$string] {
$string = ereg_replace[' +', ' ', trim[$string]];

return preg_replace["/[]/", '_', $string];
 }
5

 

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 tep_sanitize_string[$string] {
$string = ereg_replace[' +', ' ', trim[$string]];

return preg_replace["/[]/", '_', $string];
 }
6

 

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

 

Many thanks again

 

Ian

Share this post

Link to postShare on other sites

♥ecartz    724

ecartz    724

  • ♥Ambassador
  • 724
  • 3,864 posts
  • Real Name. Matt

Posted October 7, 2009

  function tep_sanitize_string[$string] {
$string = ereg_replace[' +', ' ', trim[$string]];

return preg_replace["/[]/", '_', $string];
 }
5

Try
  function tep_sanitize_string[$string] {
$string = ereg_replace[' +', ' ', trim[$string]];

return preg_replace["/[]/", '_', $string];
 }
8

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 rather than .

 

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

Share this post

Link to postShare on other sites

♥ecartz    724

ecartz    724

  • ♥Ambassador
  • 724
  • 3,864 posts
  • Real Name. Matt

Posted October 12, 2009

The github links

  • Replace ereg functions with preg functions for OSC-999
  • Replace ereg functions with preg functions for OSC-999
  • Replace split function with preg_split and explode functions for OSC-999
  • Commit cleanup and fix some warnings in phplot and typo in banners_infobox for OSC-999
  • Fix ereg->preg updates

Always back up before making changes

Share this post

Link to postShare on other sites

jlb922    0

jlb922    0

  • Các thành viên
  • 0
  • 5 bài viết
  • Real Name. jeff

Posted October 22, 2009

Can anyone help me fix this one in headertags. php?

 

$pageName = ucwords[ereg_replace["[^A-Za-z0-9]", " ", $pageName]];

 

Thanks in advance

Share this post

Link to postShare on other sites

MrPhil    648

MrPhil    648

  • Các thành viên
  • 648
  • 8,158 posts
  • Real Name. phi
  • Giới tính. một giả định

Posted October 22, 2009

Give this a try

  function tep_sanitize_string[$string] {
$string = ereg_replace[' +', ' ', trim[$string]];

return preg_replace["/[]/", '_', $string];
 }
9

Share this post

Link to postShare on other sites

steve_s    5

steve_s    5

  • Các thành viên
  • 5
  • 1,574 posts
  • Real Name. steve
  • Giới tính. một giả định
  • Location. London

Posted November 24, 2009

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

 

Vì thế

// 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 sizeof

[$column_list]] ] {
  for [$i=0, $n=sizeof[$column_list]; $i

Chủ Đề