可能重复:
将 ereg 表达式转换为 preg
我有这个功能用于过滤 wrod(坏词)形式的标题/描述。现在我在我的页面中看到了ereg_replace() is deprecated
php 错误Deprecated: Function ereg_replace() is deprecated in C:\xampp\htdocs\share\configs\functions.php on line 2750
和这个。Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\share\configs\functions.php:2747) in C:\xampp\htdocs\share\modules\signup\signup.php on line 31
什么问题?如何解决这个问题?
这是我的功能:
function filter_title($str)
{
global $config;
if ( $config['word_filters'] == '1' ) { $str = filterBadWords ( $str ); }
if ( $config['word_filters'] == '0' ) { $str=mysql_real_escape_string($str); }
//if ( $config['word_filters'] == '1' ) { $str = filterBadWords ( urlencode($str) ); }
//$newstr=str_replace('"',"'",$str);
$pats1 ='\''; $repls1 ="";
$pat[] ='\"'; $repl[] ="";
$pat[] ='\&'; $repl[] =" and ";
$pat[] ='\~'; $repl[] ="";
$pat[] ='\@'; $repl[] ="";
$pat[] ='\#'; $repl[] ="";
$pat[] ='\$'; $repl[] ="";
$pat[] ='\%'; $repl[] ="";
$pat[] ='\^'; $repl[] ="";
$pat[]='\*'; $repl[]="";
$pat[]='\('; $repl[]="";
$pat[]='\)'; $repl[]="";
$pat[]='\+'; $repl[]=" ";
$pat[]='\`'; $repl[]="";
$pat[]='\='; $repl[]="";
$pat[]='\!'; $repl[]="";
$pat[]='\['; $repl[]="";
$pat[]='\]'; $repl[]="";
$pat[]='\{'; $repl[]="";
$pat[]='\}'; $repl[]="";
$pat[]='\;'; $repl[]="";
$pat[]='\:'; $repl[]="";
$pat[]='\.'; $repl[]="";
$pat[]='\/'; $repl[]="";
$pat[]='\?'; $repl[]="";
$pat[]='\<'; $repl[]="";
$pat[]='\>'; $repl[]="";
//$pat[]='\_'; $repl[]=" ";
$pat[]="\\\\"; $repl[]="";
$pat[]='\|'; $repl[]="";
$pat[]='\,'; $repl[]="";
$pat[]='\0x'; $repl[]="";
$newstr = ereg_replace($pats1, $repls1, $str); // ---> 2747 <---
for($i=0;$pat[$i];$i++) {
$newstr = ereg_replace($pat[$i], $repl[$i], $newstr); // ---> 2750 <---
}
$newstr = preg_replace('/\s\s+/', ' ', $newstr);
return trim ( $newstr );
}
这个我的 filter_descr 函数:
function filter_descr($str)
{
//$str=mysql_real_escape_string($str);
global $config;
if ( $config['word_filters'] == '1' ) { $str = filterBadWords ( $str ); }
if ( $config['word_filters'] == '0' ) { $str = mysql_real_escape_string($str); }
//if ( $config['word_filters'] == '1' ) { $str = filterBadWords ( urlencode ( $str ) ); }
//$newstr=str_replace('"',"'",$str);
$pats1 = "\'"; $repls1 ="'";
$pat[] = '\"'; $repl[] =""";
$pat[] = '\&'; $repl[] ="&";
//$pat[] ='\~'; $repl[] ="";
//$pat[] ='\@'; $repl[] ="";
//$pat[] ='\#'; $repl[] ="";
$pat[] = '\$'; $repl[] ="";
$pat[] = '\%'; $repl[] ="";
$pat[] = '\{'; $repl[] ="";
$pat[] = '\}'; $repl[]="";
$pat[] = '\`'; $repl[]="";
//$pat[]='\/'; $repl[]="";
$pat[] = '\<'; $repl[]="";
$pat[] = '\>'; $repl[]="";
//$pat[]="\\\\"; $repl[]="";
$pat[] = '\|'; $repl[]="";
//$pat[]="\n"; $repl[]="<br>";
//$pat[]='\r'; $repl[]="<br>";
$pat[] = '\0x'; $repl[]="";
$newstr = ereg_replace($pats1, $repls1, $str);
for($i=0;$pat[$i];$i++) {
$newstr=ereg_replace($pat[$i], $repl[$i], $newstr);
}
$newstr = preg_replace('/\s\s+/', ' ', $newstr);
return trim ( $newstr );
}
PHP 注册(第 31 行评论):
session_start();
include('../../configs/config.php');
$smarty->assign('country', set_country_box(filter_title($_REQUEST['fcountry'])));
//if somebody is logged in and active, we don't need to see the registration page
if ($_SESSION["USERNAME"]!="" && $_SESSION["IS_ACTIVE"]=="1")
{
header("Location: $config[base_url]/main");
exit;
}
//if Cancel is pressed
if (filter_descr($_REQUEST[scancel])!="")
{
header("Location: $config[base_url]/main"); // ----> LINE 31 <----
exit;
}