Hi,

I am trying to remove the line termination characters \r and \n before putting them into mysql database. Is this possible using a php script?

It caused me lots of problems when cutting and pasting text from notepad into a html field which sends information to my database. If there is a \r somewhere in the script then i never see it using phpMyAdmin and I then can't understand when a query doesn't work.

For explain:

ab\r

in phpMyAdmin would appear

ab

The only way I can view this is to make an sql dump file with puts all the values in

"ab\r"

Any ideas would be really appreciated!

Thanks,

James

o.s. I notice this post has come up accurately.....

    
    $chars = array("\r","\n");
    $charReplace = "";
    
    $string = str_replace($chars, $charReplace, $string);
    
    

      You can use this code:

      
      $string="Hello world.\r\nGoodbye";
      
      $string=str_replace("\r\n", "<br>", $string);
      
      

      Cheers.

      William Geoghegan
      GEOTEK Computer Services
      - www.geotekcs.co.uk -

        thanks for your help. I will try using the str_replace function.

        I kind of hoping there might be a Strip Termination Slashes function. But str_replace seem simple enough,

        Thanks,

        James

          When PHP doesn't have a function you want, often the best solution is to make your own.

          function strip_termination($str, $replace = '')
          {
              $new_str = str_replace(array("\r", "\n"), $replace, $str);
              return $new_str;
          }

          Of course, in this case it doesn't offer much advantage over using "str_replace()". It'd probably be most useful, if at all, as a class method.

            Write a Reply...