Home > Archive > PHP DB > March 2006 > RE: [PHP-DB] Remove newlines from field
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
RE: [PHP-DB] Remove newlines from field
|
|
| Miles Thompson 2006-03-20, 6:56 pm |
| <tops snipped>
>At 04:00 PM 3/20/2006, you wrote:
>
>
>I am using a PHP script to pull information from a FoxPro database via ODBC.
>One of the fields is a memo field (large text) that contains newline
>characters. Displaying this info to the web page is fine as the newlines are
>ignored. The challenge is when I combine user entered text with the existing
>info and try to update the database. It fails with an "unrecognized command"
>because the end of field delimiter is on a different line. We're running on
>PHP 4.2.7 and I have tried using various combinations of str_replace to
>eliminate the newline characters, but I have been unsuccessful. Any
>suggestions?
>
>Giff
>
>Giff Hammar
>IT Director
>Certified Parts Warehouse
>http://www.certifiedparts.com <http://www.certifiedparts.com/> <
><http://www.certifiedparts.com/> http://www.certifiedparts.com/>
>mailto: ghammar@certifiedparts.com
>V: 603.516.1707
>F: 603.516.1702
>M: 603.490.7163
Giff,
Are you inserting back into the FoxPro table? I had to use the following to
clean up text, cut and pasted from WPfor Windows 5.2, into a textarea.
Immediately before the INSERT I also used PHP's addslashes(). The database
is MySQL.
// have to clean up the extraneous CR/LF combos
$trupara = ".\r\n"; // period+CR+LF
$dblquotpara = '"'."\r\n"; // double quote+CR+LF
$sglquotpara = "'"."\r\n"; // single quote+CR+LF
$questnpara = "?\r\n"; // question+CR+LF
$exclampara = "!\r\n"; // exclamation+CR+LF
$colonpara = ":\r\n"; // exclamation+CR+LF
$dudspc = ". \r\n"; // period+spc+CR+LF
$flspara = "\r\n"; //CR+LF
$truflag = "***"; //something unique
$txtBody = str_replace ( $trupara, $truflag, $txtBody);
$txtBody = str_replace ( $dblquotpara, "$$$", $txtBody);
$txtBody = str_replace ( $sglquotpara, "%%%", $txtBody);
$txtBody = str_replace ( $questnpara, "+++", $txtBody);
$txtBody = str_replace ( $exclampara, "!!!", $txtBody);
$txtBody = str_replace ( $colonpara, ":::", $txtBody);
$txtBody = str_replace ( $dudspc, "###", $txtBody);
$txtBody = str_replace ( $flspara, " ", $txtBody);
$txtBody = str_replace ( $truflag, ".\n\n", $txtBody);
///double quote
$txtBody = str_replace ( "$$$", '"\n', $txtBody);
///single quote
$txtBody = str_replace ( "%%%", "'\n", $txtBody);
///question mark
$txtBody = str_replace ( "+++", '?\n', $txtBody);
///exclamation mark
$txtBody = str_replace ( "!!!", '!\n', $txtBody);
///colon
$txtBody = str_replace ( ":::", ':\n', $txtBody);
///dudspace
$txtBody = str_replace ( "###", '.\n\n', $txtBody);
$txtBody = str_replace ( "\n ", "\n", $txtBody);
Hope this is helpful - Miles
PS Policy on this list is to bottom post.
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.1.385 / Virus Database: 268.2.5/284 - Release Date: 3/17/2006
| |
| Giff Hammar 2006-03-21, 9:58 pm |
|
-----Original Message-----
From: Miles Thompson [mailto:miles@allnovascotia.com]
Sent: Monday, March 20, 2006 6:17 PM
To: php-db@lists.php.net
Subject: RE: [PHP-DB] Remove newlines from field
<tops snipped>
>At 04:00 PM 3/20/2006, you wrote:
>
>
>I am using a PHP script to pull information from a FoxPro database via
ODBC.
>One of the fields is a memo field (large text) that contains newline
>characters. Displaying this info to the web page is fine as the
>newlines are ignored. The challenge is when I combine user entered text
>with the existing info and try to update the database. It fails with an
"unrecognized command"
>because the end of field delimiter is on a different line. We're
>running on PHP 4.2.7 and I have tried using various combinations of
>str_replace to eliminate the newline characters, but I have been
>unsuccessful. Any suggestions?
>
>Giff
>
>Giff Hammar
>IT Director
>Certified Parts Warehouse
>http://www.certifiedparts.com <http://www.certifiedparts.com/> <
><http://www.certifiedparts.com/> http://www.certifiedparts.com/>
>mailto: ghammar@certifiedparts.com
>V: 603.516.1707
>F: 603.516.1702
>M: 603.490.7163
Giff,
Are you inserting back into the FoxPro table? I had to use the following to
clean up text, cut and pasted from WPfor Windows 5.2, into a textarea.
Immediately before the INSERT I also used PHP's addslashes(). The database
is MySQL.
// have to clean up the extraneous CR/LF combos
$trupara = ".\r\n"; // period+CR+LF
$dblquotpara = '"'."\r\n"; // double quote+CR+LF
$sglquotpara = "'"."\r\n"; // single quote+CR+LF
$questnpara = "?\r\n"; // question+CR+LF
$exclampara = "!\r\n"; // exclamation+CR+LF
$colonpara = ":\r\n"; // exclamation+CR+LF
$dudspc = ". \r\n"; // period+spc+CR+LF
$flspara = "\r\n"; //CR+LF
$truflag = "***"; //something unique
$txtBody = str_replace ( $trupara, $truflag, $txtBody);
$txtBody = str_replace ( $dblquotpara, "$$$", $txtBody);
$txtBody = str_replace ( $sglquotpara, "%%%", $txtBody);
$txtBody = str_replace ( $questnpara, "+++", $txtBody);
$txtBody = str_replace ( $exclampara, "!!!", $txtBody);
$txtBody = str_replace ( $colonpara, ":::", $txtBody);
$txtBody = str_replace ( $dudspc, "###", $txtBody);
$txtBody = str_replace ( $flspara, " ", $txtBody);
$txtBody = str_replace ( $truflag, ".\n\n", $txtBody);
///double quote
$txtBody = str_replace ( "$$$", '"\n', $txtBody);
///single quote
$txtBody = str_replace ( "%%%", "'\n", $txtBody);
///question mark
$txtBody = str_replace ( "+++", '?\n', $txtBody);
///exclamation mark
$txtBody = str_replace ( "!!!", '!\n', $txtBody);
///colon
$txtBody = str_replace ( ":::", ':\n', $txtBody);
///dudspace
$txtBody = str_replace ( "###", '.\n\n', $txtBody);
$txtBody = str_replace ( "\n ", "\n", $txtBody);
Hope this is helpful - Miles
PS Policy on this list is to bottom post.
====
Thanks for the help! A combination of this and the nl2br finally solved the
problem and allowed me to process the update to the database. Now it's on
the figuring out why VFP doesn't accept \ to escape special characters ....
Giff
|
|
|
|
|