1

I am trying to make the output have linebreaks between each line but it seems because my string contains a somewhat more complicated output eg "$matches['id']" I am unable to add the usual \n\r lines anywhere. I have tried numerous methods. Any suggestions? Should be simple

<?php
$file = file_get_contents('page.htm'); 

// -------- PROFILEs --------
preg_match_all('#<a.*?href="(?:http://)www.site.com/profiles/(?P<id>\d+)[^‌​>]+#msi',$file, $matches); 
$profiles = $matches['id'];
$uprofiles = array_unique($profiles);
echo '<pre>',print_r($uprofiles),'</pre>';
file_put_contents('Profile.txt', $uprofiles);

// ---------- IDs ----------
preg_match_all('#<a.*?href="(?:http://)www.site.com/id/(?P<id2>\w+)[^‌​>]+#msi',$file, $matches2); 
$ids = $matches2['id2'];
$uids = array_unique($ids);
echo '<pre>',print_r($uids),'</pre>';
file_put_contents('ID.txt', $uids);

?>

sorry for being an idiot, apparently I am missing something

SuperMar1o
  • 670
  • 8
  • 23

1 Answers1

2

Try this:

file_put_contents('Profile.txt', $uprofiles . "\n");

or this since it is an array:

file_put_contents('Profile.txt', print_r($uprofiles , true));

see this post: Print array to a file

Community
  • 1
  • 1
m79lkm
  • 2,960
  • 1
  • 22
  • 22