php - Unexpected space at the begining of file -


for php courses have create note pad start sample text, when edit , click on save button, text inside file edited , saved. if refresh page / open file directly have new content edited user displayed.

it works, have unexpected space in file.

if put @ first character on first line "sample text", i'll not see "sample text" instead:

      sample text  

and that's first line, ever if edited file manually or page. next lines start @ first characters.

below notes.txt file (where notes are) after edit web page:

mes jeux préférés:
    => fallout 3
    => natural selection 2
    =&#6    2; l4d2 

i don't see strange character in @ beginning of file.

index.php:

<?php  define('fichier_de_notes', 'notes.txt'); $fichier = fopen(fichier_de_notes, 'r+');  if (array_key_exists('note', $_post)) {      $note = filter_var($_post['note'], filter_sanitize_special_chars);     ftruncate($fichier, 0);     fseek($fichier, 0);     fputs($fichier, $note);     $updatemessage = 'vos notes ont été sauvegardés!';  } else {      $note = '';      while ($ligne = fgets($fichier)) {         $note = $note . $ligne;     } }  fclose($fichier);  include 'index.phtml'; ?> 

and index.phtml:

<html lang="en"> <head>     <meta charset="utf-8">     <title>bloc note</title> </head> <body>     <h1>bloc note</h1>      <form method="post" action="index.php" >         <p>voici votre bloc note. ajoutez-y du texte et cliquer sur "sauvegarder".</p>          <textarea id="textarea" name="note" rows="16" cols="50">             <?= $note ?>         </textarea>         <br/><br/>         <label>             <input type="submit" value="sauvegarder">         </label>         <?php if (isset($updatemessage)) {             echo $updatemessage;         } ?>     </form>  </body> </html> 

i use vim , php5.

tell me if need more information.

either update html:

<textarea id="textarea" name="note" rows="16" cols="50"><?php echo $note ?></textarea> 

or in php script:

if (array_key_exists('note', $_post)) {    $_post['note'] = trim($_post['note']); //added line    $note = filter_var($_post['note'], filter_sanitize_special_chars);    ftruncate($fichier, 0);    fseek($fichier, 0);    fputs($fichier, $note);    $updatemessage = 'vos notes ont été sauvegardés!';  } else {     $note = '';     while ($ligne = fgets($fichier)) {       $note = $note . $ligne;     }  } 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -