Results 1 to 2 of 2

Thread: file_put_contents line breaks \n

  1. #1
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default file_put_contents line breaks \n

    i am trying to put line breaks in a jSon txt file with line breaks but it doesnt seem to be responding. any suggestions please, thank you
    Code:
    $i = 0;
    $entryText = '{"comments":[';
    foreach($entryList['comments'] as $commentItem) {
    	$num = $newStack[$i];
    	
    	$entryText .= "\n" . '{"index":'.$nTotal.',"text":"'.$arrTxt[$num].'","img":"'.$arrImg[$num].'"}';
    
    	$i++;
    	$nTotal--;
    	if ($i < count($newStack)) {$entryText .= ','; }
    }
    $entryText .= ']}';
    
    file_put_contents('data/cache.txt', $entryText);
    Last edited by ggalan; 09-14-2011 at 04:33 PM.

  2. #2
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    sometimes i overlook the obvious, i had it encode a .txt instead of a .json file

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •