0

log.php

define ( 'COMPANY_WEB', 'www.6666.com' );
//define ( 'COMPANY_WEB', 'www.6666.com' );
define ( 'COMPANY_FAX', 'asdfffff' );

私の文字列置換コード...

$config_old_arr[0] = " define ( 'COMPANY_WEB', 'www.6666.com' )";
$config_new_arr[0] = " define ( 'COMPANY_WEB', 'www.NEW.com' )";

$config_new_file_content = str_replace($config_old_arr, $config_new_arr, $logfilecontent);

コードを実行した後...新しいlog.phpファイルを変更します

logNew.php

define ( 'COMPANY_WEB', 'www.NEW.com' );
//define ( 'COMPANY_WEB', 'www.NEW.com' );
define ( 'COMPANY_FAX', 'asdfffff' );

ただし、コメントなしの行(1行目)の値のみを変更したいので、結果の文字列は次のようになります

logNew.php

define ( 'COMPANY_WEB', 'www.NEW.com' );
//define ( 'COMPANY_WEB', 'www.6666.com' );
define ( 'COMPANY_FAX', 'asdfffff' );

i like to use str_replace() function but that method may be not suitable for this problem Anyone know solution for this problem please help to me.

4

1 に答える 1

-1

substrを使用して、文字列の最初の 2 文字を確認します

//$linetocheck = 置き換える行

if (substr($linetocheck, 0, 2) == "//") {

    //the first 2 chars are //

}
于 2012-11-21T08:55:01.070 に答える