在osCommerce中将ereg_replace更改为preg_replace函数

时间:2014-04-22 19:50:51

标签: php oscommerce

我正在尝试将旧的osCommerce网站移动到新服务器,并对已弃用的功能提出疑问。我需要将ereg更改为preg_match。

这是原始代码:

function _filter_save_image ($products_delete_image) {
    $products_delete_image = htmlspecialchars(stripslashes($products_delete_image));
    $products_delete_image = ereg_replace('&lt;img ', '', $products_delete_image); // Remove: <img
    $products_delete_image = ereg_replace('src=', '', $products_delete_image); // Remove: src=
    $products_delete_image = ereg_replace('&quot;', '', $products_delete_image); // Remove: "
    $products_delete_image = ereg_replace('/&gt;', '', $products_delete_image); // Remove: />
    $products_delete_image = ereg_replace(HTTP_SERVER.DIR_WS_CATALOG_IMAGES, '', $products_delete_image); // Remove: absolute path
        return $products_delete_image;
}

这是我尝试修改代码:

function _filter_save_image ($products_delete_image) {
    $products_delete_image = htmlspecialchars(stripslashes($products_delete_image));
    $products_delete_image = preg_replace('/\&lt;img/', '', $products_delete_image); // Remove: <img
    $products_delete_image = preg_replace('/src=/', '', $products_delete_image); // Remove: src=
    $products_delete_image = preg_replace('/\&quot;/', '', $products_delete_image); // Remove: '
    $products_delete_image = preg_replace('/\&gt;/', '', $products_delete_image); // Remove: />
    $products_delete_image = preg_replace('/\/HTTP_SERVER.DIR_WS_CATALOG_IMAGES/', '', $products_delete_image); // Remove: absolute path
        return $products_delete_image;
}

我现在没有收到错误,但它也没有发生错误。

1 个答案:

答案 0 :(得分:1)

无需逃避&

   function _filter_save_image ($products_delete_image) {
            $products_delete_image = htmlspecialchars(stripslashes($products_delete_image));
            $products_delete_image = preg_replace('/&lt;img/', '', $products_delete_image); // Remove: <img
            $products_delete_image = preg_replace('/src=/', '', $products_delete_image); // Remove: src=
            $products_delete_image = preg_replace('/&quot;/', '', $products_delete_image); // Remove: '
            $products_delete_image = preg_replace('/&gt;/', '', $products_delete_image); // Remove: />
            $products_delete_image = preg_replace('/HTTP_SERVER.DIR_WS_CATALOG_IMAGES/', '', $products_delete_image); // Remove: absolute path
                return $products_delete_image;
            }