我正在尝试将旧的osCommerce网站移动到新服务器,并对已弃用的功能提出疑问。我需要将ereg更改为preg_match。
这是原始代码:
function _filter_save_image ($products_delete_image) {
$products_delete_image = htmlspecialchars(stripslashes($products_delete_image));
$products_delete_image = ereg_replace('<img ', '', $products_delete_image); // Remove: <img
$products_delete_image = ereg_replace('src=', '', $products_delete_image); // Remove: src=
$products_delete_image = ereg_replace('"', '', $products_delete_image); // Remove: "
$products_delete_image = ereg_replace('/>', '', $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('/\<img/', '', $products_delete_image); // Remove: <img
$products_delete_image = preg_replace('/src=/', '', $products_delete_image); // Remove: src=
$products_delete_image = preg_replace('/\"/', '', $products_delete_image); // Remove: '
$products_delete_image = preg_replace('/\>/', '', $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;
}
我现在没有收到错误,但它也没有发生错误。
答案 0 :(得分:1)
无需逃避&
function _filter_save_image ($products_delete_image) {
$products_delete_image = htmlspecialchars(stripslashes($products_delete_image));
$products_delete_image = preg_replace('/<img/', '', $products_delete_image); // Remove: <img
$products_delete_image = preg_replace('/src=/', '', $products_delete_image); // Remove: src=
$products_delete_image = preg_replace('/"/', '', $products_delete_image); // Remove: '
$products_delete_image = preg_replace('/>/', '', $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;
}