私はテキストファイルQfile.txtを持っていて、その内容は次のとおりで、同じ情報を持つ別のファイルを作成したいのですが、答えは異なります。 Qfile1.txt、Qfile2.txtWindows上の複数行のファイルコンテンツにある私のpreg_replace()が失敗するのはなぜですか?
Qfile.txt
Question "What is your age?"
Answer ""
Question "What you doing?"
Answer ""
Question "What is you name?"
Answer ""
Qfile1.txt
Question "What is your age?"
Answer "25"
Question "What you doing?"
Answer "chatting"
Question "What is you name?"
Answer "Midhun"
私はQfile.txtからの質問を読みたいです情報をQfile1.txt に保存してください。私はいくつかのコードを書いたが、パターンマッチングが機能していません。
$contents=file_get_contents("Qfile.txt");
foreach(/*bla bla*/)
{
$pattern = "/Question \"".preg_quote($id, '/')."\"\nAnswer \"\"/";
$string = str_replace('"', '\"', $string);
$replacement = "Question \"$id\"\nAnswer \"". $string . "\"";
$result = preg_replace($pattern, $replacement, $contents);
}
preg_replace($pattern, $replacement, $contents);
が機能していません。
はいWindowsマシンで作業しています。 – coderex
それはあなたの問題です。上記のコードを修正してください。 – chaos
はいその多くの作業tanQz :) – coderex