-3

Possible Duplicate:
Converting ereg expressions to preg

I have this Function For filter wrod (bad word) form title/desc. now i see ereg_replace() is deprecated php error Deprecated: Function ereg_replace() is deprecated in C:\xampp\htdocs\share\configs\functions.php on line 2750 and this 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 in my page. what's problem? how to fix this ?

This is My Function :

    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 );
}

This My filter_descr function :

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 ="&#39;";
        $pat[] = '\"';  $repl[] ="&#34;";
        $pat[] = '\&';  $repl[] ="&amp;";
        //$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 Signup ( LINE 31 commented ) :

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;
}
Community
  • 1
  • 1
BBKing
  • 2,279
  • 8
  • 38
  • 44

2 Answers2

4

Don't use ereg_replace() as it is deprecated. Use preg_replace(). From a quick glance at your function, you should be able to simply convert the functions.

As far as the headers already sent error. This is likely due to the deprecated warning message being output before you call header().

Although correcting the above should solve the problem. If this is production, you should strongly consider disabling display_errors.

Jason McCreary
  • 71,546
  • 23
  • 135
  • 174
0

When ever you use header function , then if even a single space is sent as response before you send actual output you will get error

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\share\configs\functions.php:2747)

it is good not to close php ending tag. Check have you and white space and for other errors @Json Has given the answer use preg_replace() instead.

Rajan Rawal
  • 6,171
  • 6
  • 40
  • 62