preg_replace(): Delimiter must not be alphanumeric or backslash
<pre><code>$test =array('APP_TITLE' =&gt;'ssfss');
update_define($test);

function update_define($arr_con){
    $file='config.php';
    $fileContent= file_get_contents($file);
    $i = 0;
    $define_arr = array();
    $new_value_arr = array();

    foreach ($arr_con as $constant =&gt; $vale){
        $line = getLine($constant);

        $define_arr[$i] = $line;
        if(($vale == 'true') || ($vale == 'false')){
            $new_value_arr[$i] = "define('$constant', $vale)";
        }else{
            $new_value_arr[$i] = "define('$constant', '$vale')";
        }
        $i++;
    }
    $modified=preg_replace($define_arr, $new_value_arr, $fileContent);

    file_put_contents($file, $modified);

}

function getLine($string){
    $ret = '';
    $file = fopen("config.php", "r") or exit("Unable to open file!");
    //Output a line of the file until the end is reached
    $i = 0;
    while(!feof($file))
    {
        $i++;
        $line = fgets($file);
        $pos = strpos($line, $string);
        if( $pos !== false ){
            $test =array('APP_TITLE' =&gt;'ssfss');
            update_define($test);

function update_define($arr_con){
    $file='config.php';
    $fileContent= file_get_contents($file);
    $i = 0;
    $define_arr = array();
    $new_value_arr = array();

            foreach ($arr_con as $constant =&gt; $vale){
                $line = getLine($constant);

                $define_arr[$i] = $line;
                if(($vale == 'true') || ($vale == 'false')){
                    $new_value_arr[$i] = "define('$constant', $vale)";
                }else{
                    $new_value_arr[$i] = "define('$constant', '$vale')";
                }
                $i++;
                }
                $modified=preg_replace($define_arr, $new_value_arr, $fileContent);

                file_put_contents($file, $modified);

            }

        function getLine($string)
        {

        $ret = '';
            $file = fopen("config.php", "r") or exit("Unable to open file!");
            //Output a line of the file until the end is reached
            $i = 0;
            while(!feof($file))
            {
                $i++;
                $line = fgets($file);
                $pos = strpos($line, $string);
                if( $pos !== false ){
                    //          echo $i.'&lt;br/&gt;';
                    $line = str_replace("define(", "define\(",$line);
                    $line = str_replace(");","\);", $line);
                    $ret= $line;
                }
            }
            fclose($file);
            return $ret;
        }
                $line = str_replace("define(", "define\(",$line);
                    $line = str_replace(");","\);", $line);
                    $ret= $line;
                }
            }
            fclose($file);
            return $ret;
        }
</code></pre>

<p>config.php file</p>

<pre><code>&lt;?PHP
    define ( 'APP_TITLE', 'test com title' ); 
    define('COMPANY_ADDRESS_2', '49 sd d');
    define('COMPANY_ZIPCODE', '2085');
    define('COMPANY_PHONE', '+44 (0)2 8007-5554');
    define('COMPANY_FAX', '+62 (0)2 253-9479');
?&gt;
</code></pre>

<p>above code gave to me below error</p>

<pre><code>Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in /opt/lampp/htdocs/Edit_file/abc.php on line 46
Array ( [0] =&gt; define\('APP_TITLE', 'test com title' \); ) /nArray ( [0] =&gt; define('APP_TITLE', 'ssfss') ) 
</code></pre>

<p>i' were tring to edit some php file using my above method but calling preg_replace() method give me some errors. please help to solve this problem</p>
