-1

I am using urldecode data for writing a content in to a text file, but in that file all the contents are showing together(not aligned expected) in windows notepad(in windows wordpad it is coming correctly), also when i open it in Ubuntu contents are coming correctly(my contents have enter key and spaces some special characters too).

$attachment_file = fopen(Yii::app()->basePath.'/../uploads/attachment'.$user_id.'.txt', "a+") or die("Unable to open file!");   

$content         = urldecode($note_data["note_data"]);

fwrite($attachment_file,$content);
fclose($attachment_file);

For the quick fix i did

$content = str_replace("\n","\r\n",$content);

but i want to know is there any other methods to do it.

Naveenbos
  • 2,532
  • 3
  • 34
  • 60
  • 1
    because spaces are replaced with %20 why the hell you want to use urlencode for it? – Robert Aug 27 '14 at 13:55
  • Robert the urlencode data coming from the Iphone and Ipad to the backend, here we are using yii for manipulating the data and do some other stuff too. – Naveenbos Aug 27 '14 at 13:56
  • so if words are divided you can have problem with line ending which is different in Unix systems and Windows try doing something like `str_replace("\n", "\r\n", $content);` to replace unix EOL for windows EOL. – Robert Aug 28 '14 at 08:39

1 Answers1

1

If you are using Linux to create the file, you should manually add this. If you use Windows, You can try str_replace("\n", PHP_EOL, $content) instead.

I don't understand why you are doing urldecode. Maybe you should use something like utf8_decode if you have your data in utf-8 format.

  • Server is accepting data in json encoded format, from the ios front end they are sending data to urlencode format, i am not familiar with the ios development, server side getting data contains the spaces and enters and special characters – Naveenbos Aug 28 '14 at 05:38