I wrote a function to insert some text into a txt file (using a foreach), but I'd like to go in a new line for each element. Any suggestiong?
This is my function:
function process_page($page) {
$html = get_html($page);
foreach($html->find("h1") as $div) {
$show = $div;
$show = strip_tags($show);
$data = '\n' . $show;
$ret = file_put_contents('mydata.txt', $data, FILE_APPEND | LOCK_EX);
if($ret === false) {
die('There was an error writing this file');
}
else {
echo "$ret bytes written to file";
}
}
}
I tried to insert '\n'
but it write it into text file