循环通过 php 中的文本文件,我使用 preg_match 来检测该行是否包含“default”,并在该单词后放置一个逗号而不是空格,但它不起作用:
$FSCS = "";
//Read the txt file
if(($handle = fopen("FSCS.txt", "r")) != false)
{
//Loop through each line
while(($data = fgetcsv($handle, 1000, ",")) != false)
{
if(preg_match("/default/", $data[0])) $FSCS .= str_replace("default ", "default,", trim($data[0]))."\n";
else $FSCS .= trim($data[0]).",";
}
}
每一行都由“else”语句处理