Bir metin dosyası Qfile.txt var ve içerikleri aşağıda sunulmuştur, ve aynı bilgiler ile başka bir dosya oluşturmak istiyor ve ama cevaplar diffrent bulunmaktadır. Qfile1.txt, Qfile2.txt
Qfile.txt strong>
Question "What is your age?"
Answer ""
Question "What you doing?"
Answer ""
Question "What is you name?"
Answer ""
Qfile1.txt strong>
Question "What is your age?"
Answer "25"
Question "What you doing?"
Answer "chatting"
Question "What is you name?"
Answer "Midhun"
I want to read the questions from the Qfile.txt and store the informations to Qfile1.txt with in PHP. I wrote some code but the pattern matching is not working:
$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);
çalışmıyor.