<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: nl2br() - won't work with variables? in Tech Help - Software/Hardware etc</title>
    <link>https://community.plus.net/t5/Tech-Help-Software-Hardware-etc/nl2br-won-t-work-with-variables/m-p/586479#M17626</link>
    <description>What does $array look like before calling stripslashes? i.e. do a print_r($array). I suspect you will only see a single slash in the data because php is using the first \ as a delimiter to ensure the second \ appears in the string. You thn call stripslashes??? which gets rid of the first and only \ and not the two \\ you thought was there.&lt;BR /&gt;Also what does stripslashes_deep() do as I'm not familiar with that function. If that is not a php function it may have a problem (or the data does only have one \ as detailed above). Instead of doing an array try with several variables and use stripslashes() instead of stripslashes_deep() as an experiment.&lt;BR /&gt;mysql_real_escape_string is used prior to writing data to a mysql database and should not be used for general string manipulation to screen as it also escapes certain other characters that can cause issues when writing to a database.&lt;BR /&gt;never used nl2br(), I just use mysql_real_escape_string() in a function to format the text prior to writing to the DB and just use what I get back from the DB in the textarea when displaying what the user typed in. I also strip out all \r\n and replace with a space in emails.&lt;BR /&gt;You also need to read up on the difference between surrounding text with a single quote or a double quote. &lt;BR /&gt;e.g. print '\r\nhello\r\n' will show \r\nhello\r\n&lt;BR /&gt;print "\r\nhello\r\n" will show &amp;lt;cr&amp;gt;&amp;lt;lf&amp;gt;hello&amp;lt;cr&amp;gt;&amp;lt;lf&amp;gt; where &amp;lt;cr&amp;gt; is a carriage return character and &amp;lt;lf&amp;gt; a line feed character.&lt;BR /&gt;in other words escaped characters (\?) are interpreted and converted within text surrounded by double quotes but left as is with text surrounded with single quotes.&lt;BR /&gt;This also explains your str_replace() problems...&lt;BR /&gt;double quote example: str_replace("\r\n", " ", $string) is looking for 2 characters &amp;lt;cr&amp;gt; and &amp;lt;lf&amp;gt; because \r is seen as a single char and \n also a single char. You could do str_replace("\r\n", '\r\n', $string) which will replace &amp;lt;cr&amp;gt;&amp;lt;lf&amp;gt; with 4 characters \r\n&lt;BR /&gt;single quote example: str_replace('\r\n', " ", $string) is looking to match 4 characters \ r \ and n and replace all 4 with a single space. So you could do... str_replace('\r\n', "\r\n", $string) which will replace the 4 characters \r\n with 2 characters &amp;lt;cr&amp;gt;&amp;lt;lf&amp;gt;.&lt;BR /&gt;</description>
    <pubDate>Fri, 09 Jan 2009 18:45:58 GMT</pubDate>
    <dc:creator>Peter_Vaughan</dc:creator>
    <dc:date>2009-01-09T18:45:58Z</dc:date>
    <item>
      <title>nl2br() - won't work with variables?</title>
      <link>https://community.plus.net/t5/Tech-Help-Software-Hardware-etc/nl2br-won-t-work-with-variables/m-p/586471#M17618</link>
      <description>Hi&lt;BR /&gt;On my site I'm trying to use a &amp;lt;Textarea&amp;gt; as an input for an email form. When I send the email comes out with new lines formattred with \r\n which is rather annoying as the format isn't kept.&lt;BR /&gt;So.. I tried using $Message = nl2br($Message); but it doesn't work. It doesn't even strip out \r\n yet alone replace it with the br tag.&lt;BR /&gt;When I tried:&lt;BR /&gt;$Message2 = "This is\r\n a test\r\n\r\n to see if it works";&lt;BR /&gt;$Message2 = nl2br($Message2);&lt;BR /&gt;It worked flawlessly.&lt;BR /&gt;Why?&lt;BR /&gt;Here is the exact code in my script:&lt;BR /&gt;Print "$Message&amp;lt;BR&amp;gt;";&lt;BR /&gt;$Message2 = nl2br("$Message"); (Also tried without " " characters)&lt;BR /&gt;Print "$Message2&amp;lt;BR&amp;gt;";&lt;BR /&gt;$Message2 = "This is\r\n a test\r\n\r\n to see if it works";&lt;BR /&gt;Print "$Message2&amp;lt;BR&amp;gt;";&lt;BR /&gt;$Message2 = nl2br($Message2);&lt;BR /&gt;Print "$Message2&amp;lt;BR&amp;gt;";</description>
      <pubDate>Fri, 09 Jan 2009 14:50:34 GMT</pubDate>
      <guid>https://community.plus.net/t5/Tech-Help-Software-Hardware-etc/nl2br-won-t-work-with-variables/m-p/586471#M17618</guid>
      <dc:creator>7up</dc:creator>
      <dc:date>2009-01-09T14:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: nl2br() - won't work with variables?</title>
      <link>https://community.plus.net/t5/Tech-Help-Software-Hardware-etc/nl2br-won-t-work-with-variables/m-p/586472#M17619</link>
      <description>just to make matters worse php seems to be randomly dropping dead or getting lazy:&lt;BR /&gt;$Message = str_replace("\r\n", "\n", $Message);&lt;BR /&gt;Doesn't work either&amp;nbsp; &lt;img class="lia-deferred-image lia-image-emoji" src="https://community.plus.net/html/@5CA762C7B9B1D4AB36AAB959133ED0B4/images/emoticons/angry.gif" alt="Angry" title="Angry" /&gt; &lt;BR /&gt;This is crazy. How can php decide it won't execute the same lines of code???</description>
      <pubDate>Fri, 09 Jan 2009 16:01:47 GMT</pubDate>
      <guid>https://community.plus.net/t5/Tech-Help-Software-Hardware-etc/nl2br-won-t-work-with-variables/m-p/586472#M17619</guid>
      <dc:creator>7up</dc:creator>
      <dc:date>2009-01-09T16:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: nl2br() - won't work with variables?</title>
      <link>https://community.plus.net/t5/Tech-Help-Software-Hardware-etc/nl2br-won-t-work-with-variables/m-p/586473#M17620</link>
      <description>Well, after 20 views of people who obviously know what nl2br() means (or you wouldn't be reading this) I've worked something out:&lt;BR /&gt;str_replace() only likes single quotes not double quotes.&lt;BR /&gt;Unfortunately the \n still isn't being recognised by the browser and instead if being printed.&lt;BR /&gt;Will one of you PLEASE help me?</description>
      <pubDate>Fri, 09 Jan 2009 17:09:13 GMT</pubDate>
      <guid>https://community.plus.net/t5/Tech-Help-Software-Hardware-etc/nl2br-won-t-work-with-variables/m-p/586473#M17620</guid>
      <dc:creator>7up</dc:creator>
      <dc:date>2009-01-09T17:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: nl2br() - won't work with variables?</title>
      <link>https://community.plus.net/t5/Tech-Help-Software-Hardware-etc/nl2br-won-t-work-with-variables/m-p/586474#M17621</link>
      <description>Sorry - I read every post to get it out of my unread posts list.&lt;BR /&gt;Apologies that this isn't an answer to your query, I know rather little about coding.&amp;nbsp; Well, probably nothing at all.</description>
      <pubDate>Fri, 09 Jan 2009 17:11:02 GMT</pubDate>
      <guid>https://community.plus.net/t5/Tech-Help-Software-Hardware-etc/nl2br-won-t-work-with-variables/m-p/586474#M17621</guid>
      <dc:creator>James</dc:creator>
      <dc:date>2009-01-09T17:11:02Z</dc:date>
    </item>
    <item>
      <title>Re: nl2br() - won't work with variables?</title>
      <link>https://community.plus.net/t5/Tech-Help-Software-Hardware-etc/nl2br-won-t-work-with-variables/m-p/586475#M17622</link>
      <description>You realise at the bottom of the topic list there is a link that says 'Mark Read' right? - That will do the job for you in an instant &lt;img class="lia-deferred-image lia-image-emoji" src="https://community.plus.net/html/@0FA1396AC0773F33E2DC472BB4F75D3C/images/emoticons/wink.gif" alt="Wink" title="Wink" /&gt;</description>
      <pubDate>Fri, 09 Jan 2009 17:18:05 GMT</pubDate>
      <guid>https://community.plus.net/t5/Tech-Help-Software-Hardware-etc/nl2br-won-t-work-with-variables/m-p/586475#M17622</guid>
      <dc:creator>7up</dc:creator>
      <dc:date>2009-01-09T17:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: nl2br() - won't work with variables?</title>
      <link>https://community.plus.net/t5/Tech-Help-Software-Hardware-etc/nl2br-won-t-work-with-variables/m-p/586476#M17623</link>
      <description>wish I had done that had enough abuse already today from other people</description>
      <pubDate>Fri, 09 Jan 2009 17:21:35 GMT</pubDate>
      <guid>https://community.plus.net/t5/Tech-Help-Software-Hardware-etc/nl2br-won-t-work-with-variables/m-p/586476#M17623</guid>
      <dc:creator>pierre_pierre</dc:creator>
      <dc:date>2009-01-09T17:21:35Z</dc:date>
    </item>
    <item>
      <title>Re: nl2br() - won't work with variables?</title>
      <link>https://community.plus.net/t5/Tech-Help-Software-Hardware-etc/nl2br-won-t-work-with-variables/m-p/586477#M17624</link>
      <description>Right... it's got something to do with the newline \n character.&lt;BR /&gt;If I hard code it like:&lt;BR /&gt;Print "This\nis\na\ntest"&lt;BR /&gt;the browser won't display the \n BUT the source is correctly formatted.&lt;BR /&gt;If I use&lt;BR /&gt;Print $Message;&lt;BR /&gt;It WILL print the \n on the actual webpage.&lt;BR /&gt;Why?</description>
      <pubDate>Fri, 09 Jan 2009 17:41:41 GMT</pubDate>
      <guid>https://community.plus.net/t5/Tech-Help-Software-Hardware-etc/nl2br-won-t-work-with-variables/m-p/586477#M17624</guid>
      <dc:creator>7up</dc:creator>
      <dc:date>2009-01-09T17:41:41Z</dc:date>
    </item>
    <item>
      <title>Re: nl2br() - won't work with variables?</title>
      <link>https://community.plus.net/t5/Tech-Help-Software-Hardware-etc/nl2br-won-t-work-with-variables/m-p/586478#M17625</link>
      <description>Finally... not that anyone cares despite reading...&lt;BR /&gt;mysql_real_escape_string is responsible. It adds an extra slash so... \r\n becomes \\r\\n.</description>
      <pubDate>Fri, 09 Jan 2009 18:06:04 GMT</pubDate>
      <guid>https://community.plus.net/t5/Tech-Help-Software-Hardware-etc/nl2br-won-t-work-with-variables/m-p/586478#M17625</guid>
      <dc:creator>7up</dc:creator>
      <dc:date>2009-01-09T18:06:04Z</dc:date>
    </item>
    <item>
      <title>Re: nl2br() - won't work with variables?</title>
      <link>https://community.plus.net/t5/Tech-Help-Software-Hardware-etc/nl2br-won-t-work-with-variables/m-p/586479#M17626</link>
      <description>What does $array look like before calling stripslashes? i.e. do a print_r($array). I suspect you will only see a single slash in the data because php is using the first \ as a delimiter to ensure the second \ appears in the string. You thn call stripslashes??? which gets rid of the first and only \ and not the two \\ you thought was there.&lt;BR /&gt;Also what does stripslashes_deep() do as I'm not familiar with that function. If that is not a php function it may have a problem (or the data does only have one \ as detailed above). Instead of doing an array try with several variables and use stripslashes() instead of stripslashes_deep() as an experiment.&lt;BR /&gt;mysql_real_escape_string is used prior to writing data to a mysql database and should not be used for general string manipulation to screen as it also escapes certain other characters that can cause issues when writing to a database.&lt;BR /&gt;never used nl2br(), I just use mysql_real_escape_string() in a function to format the text prior to writing to the DB and just use what I get back from the DB in the textarea when displaying what the user typed in. I also strip out all \r\n and replace with a space in emails.&lt;BR /&gt;You also need to read up on the difference between surrounding text with a single quote or a double quote. &lt;BR /&gt;e.g. print '\r\nhello\r\n' will show \r\nhello\r\n&lt;BR /&gt;print "\r\nhello\r\n" will show &amp;lt;cr&amp;gt;&amp;lt;lf&amp;gt;hello&amp;lt;cr&amp;gt;&amp;lt;lf&amp;gt; where &amp;lt;cr&amp;gt; is a carriage return character and &amp;lt;lf&amp;gt; a line feed character.&lt;BR /&gt;in other words escaped characters (\?) are interpreted and converted within text surrounded by double quotes but left as is with text surrounded with single quotes.&lt;BR /&gt;This also explains your str_replace() problems...&lt;BR /&gt;double quote example: str_replace("\r\n", " ", $string) is looking for 2 characters &amp;lt;cr&amp;gt; and &amp;lt;lf&amp;gt; because \r is seen as a single char and \n also a single char. You could do str_replace("\r\n", '\r\n', $string) which will replace &amp;lt;cr&amp;gt;&amp;lt;lf&amp;gt; with 4 characters \r\n&lt;BR /&gt;single quote example: str_replace('\r\n', " ", $string) is looking to match 4 characters \ r \ and n and replace all 4 with a single space. So you could do... str_replace('\r\n', "\r\n", $string) which will replace the 4 characters \r\n with 2 characters &amp;lt;cr&amp;gt;&amp;lt;lf&amp;gt;.&lt;BR /&gt;</description>
      <pubDate>Fri, 09 Jan 2009 18:45:58 GMT</pubDate>
      <guid>https://community.plus.net/t5/Tech-Help-Software-Hardware-etc/nl2br-won-t-work-with-variables/m-p/586479#M17626</guid>
      <dc:creator>Peter_Vaughan</dc:creator>
      <dc:date>2009-01-09T18:45:58Z</dc:date>
    </item>
  </channel>
</rss>

