0

xml ファイル内のサーバーのアドレスを置き換えたい。プレースホルダーをオンラインに配置%scr_path%しました。

<property id="urlGenerateImage">%scr_path%/imgcap.php</property> 

次のコードを使用する

$path=$wsurl."core/contents/tests";
//read the entire string
$str=implode("\n",file('../includes/ckeditor/plugins/fmath_formula/dialogs/configMathMLEditor.xml'));

$fp=fopen('../includes/ckeditor/plugins/fmath_formula/dialogs/configMathMLEditor.xml','w');
//replace something in the file string 
$str=str_replace('%scr_path%',$path,$str);

//now, TOTALLY rewrite the file
fwrite($fp,$str,strlen($str));

間違ったファイル パスに関するエラーが大量に発生します。パスを 2 回チェックしました。どうしたの?

4

1 に答える 1

1

それはすべて、スクリプトが実行されているディレクトリによって異なります。相対パス名 (../) を使用しているため、スクリプトが現在どのディレクトリにあるかを確認することをお勧めします。常に機能するようにスクリプトの先頭に配置します。

$path = $wsurl."core/contents/tests";

// change directory to project root
chdir("/your/project/directory");

// read the file into a string
$filename = 'includes/ckeditor/plugins/fmath_formula/dialogs/configMathMLEditor.xml';
$str = file_get_contents($filename);

// replace token
$str = str_replace('%scr_path%',$path,$str);

// save file
file_put_contents($filename, $str);
于 2011-11-23T00:54:16.427 に答える