
problems with saving and retrieving data with new line (\n and \r\n)and slashes from mysql database
Before storing information from a form in database I perform follwing
operations on it :
$path =
mysql_real_escape_string(strip_tags(trim(urldecode($_POST['p ath']))));
$summary =
mysql_real_escape_string(strip_tags(trim(urldecode($_POST['s ummary']))))
When I look in database I see '\r\n' in the text for the summary
wherever I pressed return-key.
When i retrieve the information from database and display it on webpage
'\r\n' is displayed even when I use
nl2br or
str_replace("\r\n", "<br/>", $content) or
str_replace(array("\r\n", "\n", "\r"), "<br>", $text) or
preg_replace("/\r\n|\n|\r/", "<br>", $text)
the '\r\n' is replaced with a <br>.
How is the possible ? The functions work when I let them handle a string
like "A little bit of\r\ntext".
A folder is stored as 'H:\\\\My Pictures\\\\Anemone.jpg' in the
database. When I want to display the folder I use the function
stripslashes first but then I still get 'H:\\My Pictures\\Anemone.jpg'.
Why should I apply stripslashes twice ?
Hope you can help me,
JM!
Re: problems with saving and retrieving data with new line (\n and \r\n) and slashes from mysql data
In article <Haadnd6dl8LDhjTYRVnyigA [at] scarlet.biz>, JM <reply [at] group.svp>
wrote:
> Before storing information from a form in database I perform follwing
> operations on it :
> $path =
> mysql_real_escape_string(strip_tags(trim(urldecode($_POST['p ath']))));
> $summary =
> mysql_real_escape_string(strip_tags(trim(urldecode($_POST['s ummary']))))
>
> When I look in database I see '\r\n' in the text for the summary
> wherever I pressed return-key.
> When i retrieve the information from database and display it on webpage
> '\r\n' is displayed even when I use
> nl2br or
> str_replace("\r\n", "<br/>", $content) or
> str_replace(array("\r\n", "\n", "\r"), "<br>", $text) or
> preg_replace("/\r\n|\n|\r/", "<br>", $text)
> the '\r\n' is replaced with a <br>.
> How is the possible ? The functions work when I let them handle a string
> like "A little bit of\r\ntext".
>
> A folder is stored as 'H:\\\\My Pictures\\\\Anemone.jpg' in the
> database. When I want to display the folder I use the function
> stripslashes first but then I still get 'H:\\My Pictures\\Anemone.jpg'.
> Why should I apply stripslashes twice ?
>
> Hope you can help me,
>
> JM!
<snip>
magic_quotes_runtime boolean
If magic_quotes_runtime is enabled, most functions that return data
from any sort of external source including databases and text files
will have quotes escaped with a backslash.
</snip>
See get_magic_quotes_gpc() in the docs.
You can easily add code to account for this possibility:
get_magic_quotes_gpc() && $str = strip_tags( $str );
I'm also willing to bet that your line breaks are currently double
escaped e.g. "\\r\\n".
--
Koncept <<
"The snake that cannot shed its skin perishes. So do the spirits who are
prevented from changing their opinions; they cease to be a spirit." -Nietzsche
Re: problems with saving and retrieving data with new line (\n and \r\n) and slashes from mysql data
In article <Haadnd6dl8LDhjTYRVnyigA [at] scarlet.biz>, JM <reply [at] group.svp>
wrote:
> Before storing information from a form in database I perform follwing
> operations on it :
> $path =
> mysql_real_escape_string(strip_tags(trim(urldecode($_POST['p ath']))));
> $summary =
> mysql_real_escape_string(strip_tags(trim(urldecode($_POST['s ummary']))))
>
> When I look in database I see '\r\n' in the text for the summary
> wherever I pressed return-key.
> When i retrieve the information from database and display it on webpage
> '\r\n' is displayed even when I use
> nl2br or
> str_replace("\r\n", "<br/>", $content) or
> str_replace(array("\r\n", "\n", "\r"), "<br>", $text) or
> preg_replace("/\r\n|\n|\r/", "<br>", $text)
> the '\r\n' is replaced with a <br>.
> How is the possible ? The functions work when I let them handle a string
> like "A little bit of\r\ntext".
>
> A folder is stored as 'H:\\\\My Pictures\\\\Anemone.jpg' in the
> database. When I want to display the folder I use the function
> stripslashes first but then I still get 'H:\\My Pictures\\Anemone.jpg'.
> Why should I apply stripslashes twice ?
>
> Hope you can help me,
>
> JM!
<snip>
magic_quotes_runtime boolean
If magic_quotes_runtime is enabled, most functions that return data
from any sort of external source including databases and text files
will have quotes escaped with a backslash.
</snip>
See get_magic_quotes_gpc() in the docs.
You can easily add code to account for this possibility:
get_magic_quotes_gpc() && $str = strip_tags( $str );
I'm also willing to bet that your line breaks are currently double
escaped e.g. "\\r\\n".
--
Koncept <<
"The snake that cannot shed its skin perishes. So do the spirits who are
prevented from changing their opinions; they cease to be a spirit." -Nietzsche
Re: How to correctly store and retrieve input from a textarea (withLF and CR) in MySQL ?
Koncept wrote:
> In article <Haadnd6dl8LDhjTYRVnyigA [at] scarlet.biz>, JM <reply [at] group.svp>
> wrote:
>
>> Before storing information from a form in database I perform follwing
>> operations on it :
>> $path =
>> mysql_real_escape_string(strip_tags(trim(urldecode($_POST['p ath']))));
>> $summary =
>> mysql_real_escape_string(strip_tags(trim(urldecode($_POST['s ummary']))))
>>
>> When I look in database I see '\r\n' in the text for the summary
>> wherever I pressed return-key.
>> When i retrieve the information from database and display it on webpage
>> '\r\n' is displayed even when I use
>> nl2br or
>> str_replace("\r\n", "<br/>", $content) or
>> str_replace(array("\r\n", "\n", "\r"), "<br>", $text) or
>> preg_replace("/\r\n|\n|\r/", "<br>", $text)
>> the '\r\n' is replaced with a <br>.
>> How is the possible ? The functions work when I let them handle a string
>> like "A little bit of\r\ntext".
>>
>> A folder is stored as 'H:\\\\My Pictures\\\\Anemone.jpg' in the
>> database. When I want to display the folder I use the function
>> stripslashes first but then I still get 'H:\\My Pictures\\Anemone.jpg'.
>> Why should I apply stripslashes twice ?
>>
>> Hope you can help me,
>>
>> JM!
>
> <snip>
> magic_quotes_runtime boolean
>
> If magic_quotes_runtime is enabled, most functions that return data
> from any sort of external source including databases and text files
> will have quotes escaped with a backslash.
> </snip>
>
> See get_magic_quotes_gpc() in the docs.
>
> You can easily add code to account for this possibility:
> get_magic_quotes_gpc() && $str = strip_tags( $str );
>
> I'm also willing to bet that your line breaks are currently double
> escaped e.g. "\\r\\n".
>
If I take get_magic_quotes_gpc() into consideration it now works fine
except for line feeds and carriage returns.
if (get_magic_quotes_gpc()) {
$sq = stripslashes($_POST['Summary']));
} else {
$sq = $_POST['ShortDesc'];
}
$Summary = mysql_real_escape_string(strip_tags(trim(urldecode($sq))));
This code works for quotes en uri's. But whatever combinations I've
tried including using nl2br on storing and/or retrieving. It doesn't
work for line feeds and carriage returns.
Either \r\n is displayed on webpage or rn.
How to correctly store and retrieve input from a textarea (with LF and
CR) in MySQL ?
JM
Re: How to correctly store and retrieve input from a textarea (withLF and CR) in MySQL ?
Koncept wrote:
> In article <Haadnd6dl8LDhjTYRVnyigA [at] scarlet.biz>, JM <reply [at] group.svp>
> wrote:
>
>> Before storing information from a form in database I perform follwing
>> operations on it :
>> $path =
>> mysql_real_escape_string(strip_tags(trim(urldecode($_POST['p ath']))));
>> $summary =
>> mysql_real_escape_string(strip_tags(trim(urldecode($_POST['s ummary']))))
>>
>> When I look in database I see '\r\n' in the text for the summary
>> wherever I pressed return-key.
>> When i retrieve the information from database and display it on webpage
>> '\r\n' is displayed even when I use
>> nl2br or
>> str_replace("\r\n", "<br/>", $content) or
>> str_replace(array("\r\n", "\n", "\r"), "<br>", $text) or
>> preg_replace("/\r\n|\n|\r/", "<br>", $text)
>> the '\r\n' is replaced with a <br>.
>> How is the possible ? The functions work when I let them handle a string
>> like "A little bit of\r\ntext".
>>
>> A folder is stored as 'H:\\\\My Pictures\\\\Anemone.jpg' in the
>> database. When I want to display the folder I use the function
>> stripslashes first but then I still get 'H:\\My Pictures\\Anemone.jpg'.
>> Why should I apply stripslashes twice ?
>>
>> Hope you can help me,
>>
>> JM!
>
> <snip>
> magic_quotes_runtime boolean
>
> If magic_quotes_runtime is enabled, most functions that return data
> from any sort of external source including databases and text files
> will have quotes escaped with a backslash.
> </snip>
>
> See get_magic_quotes_gpc() in the docs.
>
> You can easily add code to account for this possibility:
> get_magic_quotes_gpc() && $str = strip_tags( $str );
>
> I'm also willing to bet that your line breaks are currently double
> escaped e.g. "\\r\\n".
>
If I take get_magic_quotes_gpc() into consideration it now works fine
except for line feeds and carriage returns.
if (get_magic_quotes_gpc()) {
$sq = stripslashes($_POST['Summary']));
} else {
$sq = $_POST['ShortDesc'];
}
$Summary = mysql_real_escape_string(strip_tags(trim(urldecode($sq))));
This code works for quotes en uri's. But whatever combinations I've
tried including using nl2br on storing and/or retrieving. It doesn't
work for line feeds and carriage returns.
Either \r\n is displayed on webpage or rn.
How to correctly store and retrieve input from a textarea (with LF and
CR) in MySQL ?
JM
Re: How to correctly store and retrieve input from a textarea (withLF and CR) in MySQL ?
Koncept wrote:
> In article <Haadnd6dl8LDhjTYRVnyigA [at] scarlet.biz>, JM <reply [at] group.svp>
> wrote:
>
>> Before storing information from a form in database I perform follwing
>> operations on it :
>> $path =
>> mysql_real_escape_string(strip_tags(trim(urldecode($_POST['p ath']))));
>> $summary =
>> mysql_real_escape_string(strip_tags(trim(urldecode($_POST['s ummary']))))
>>
>> When I look in database I see '\r\n' in the text for the summary
>> wherever I pressed return-key.
>> When i retrieve the information from database and display it on webpage
>> '\r\n' is displayed even when I use
>> nl2br or
>> str_replace("\r\n", "<br/>", $content) or
>> str_replace(array("\r\n", "\n", "\r"), "<br>", $text) or
>> preg_replace("/\r\n|\n|\r/", "<br>", $text)
>> the '\r\n' is replaced with a <br>.
>> How is the possible ? The functions work when I let them handle a string
>> like "A little bit of\r\ntext".
>>
>> A folder is stored as 'H:\\\\My Pictures\\\\Anemone.jpg' in the
>> database. When I want to display the folder I use the function
>> stripslashes first but then I still get 'H:\\My Pictures\\Anemone.jpg'.
>> Why should I apply stripslashes twice ?
>>
>> Hope you can help me,
>>
>> JM!
>
> <snip>
> magic_quotes_runtime boolean
>
> If magic_quotes_runtime is enabled, most functions that return data
> from any sort of external source including databases and text files
> will have quotes escaped with a backslash.
> </snip>
>
> See get_magic_quotes_gpc() in the docs.
>
> You can easily add code to account for this possibility:
> get_magic_quotes_gpc() && $str = strip_tags( $str );
>
> I'm also willing to bet that your line breaks are currently double
> escaped e.g. "\\r\\n".
>
If I take get_magic_quotes_gpc() into consideration it now works fine
except for line feeds and carriage returns.
if (get_magic_quotes_gpc()) {
$sq = stripslashes($_POST['Summary']));
} else {
$sq = $_POST['ShortDesc'];
}
$Summary = mysql_real_escape_string(strip_tags(trim(urldecode($sq))));
This code works for quotes en uri's. But whatever combinations I've
tried including using nl2br on storing and/or retrieving. It doesn't
work for line feeds and carriage returns.
Either \r\n is displayed on webpage or rn.
How to correctly store and retrieve input from a textarea (with LF and
CR) in MySQL ?
JM
Re: How to correctly store and retrieve input from a textarea (withLF and CR) in MySQL ?
Try this: http://www.michikono.com/code/DbSafe/DbSafe.php
Re: How to correctly store and retrieve input from a textarea (withLF and CR) in MySQL ?
Try this: http://www.michikono.com/code/DbSafe/DbSafe.php
Re: How to correctly store and retrieve input from a textarea (withLF and CR) in MySQL ?
Try this: http://www.michikono.com/code/DbSafe/DbSafe.php
PHP » alt.php » problems with saving and retrieving data with new line (\n and \r\n)and slashes from mysql database