我正在从另一个网站获取数据,删除我不需要的数据。并想将我收集的信息存储到一个文件中。我已经完成了我需要的一切,但我的文件每行都写入数组
这是我正在处理的代码:
$xml = simplexml_load_file('website.xml');
$item_array = array();
$item_array[0] = 0;
$item_array[1] = 2;
$item_array[2] = 4;
$item_array[3] = 6;
$item_array[4] = 8;
$item_array[5] = 9;
$item_array[6] = 10;
$item_array[7] = 11;
$item_array[8] = 12;
$item_array[9] = 13;
$item_array[10] = 14;
$item_array[11] = 15;
$item_array[12] = 16;
$patterns = array();
$patterns[0] = '/Sum It Up/';
$patterns[1] = '/=/';
$patterns[2] = '/Powerball/';
$patterns[3] = '/MegaBall/';
$patterns[4] = '/Megaplier/';
$patterns[5] = '/Bonus Ball/';
$print = array();
foreach($item_array as $news){
echo $xml->channel->item[$news]->title.'<br>';
$new_string = $xml->channel->item[$news]->description;
$new_string = preg_replace("/[^A-Za-z0-9 ]/", '', $new_string);
$new_string = preg_replace($patterns, '', $new_string);
echo $new_string.'<br>';
$print[] = array($new_string);
}
$filename = 'numbers.txt';
$handle = fopen($filename, 'w');
@$output = implode("\r\n", $print);
fwrite($handle, $output);
fclose($handle);
我只想将数字保留为数组并将数字逐行写入文件。