Remove newlines from field

Remove newlines from field

am 20.03.2006 23:00:49 von Giff Hammar

------=_NextPart_000_0099_01C64C3F.D6D87B40
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit

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
mailto: ghammar@certifiedparts.com
V: 603.516.1707
F: 603.516.1702
M: 603.490.7163


------=_NextPart_000_0099_01C64C3F.D6D87B40--

RE: Remove newlines from field

am 20.03.2006 23:11:12 von Bastien Koert

see the nl2br function in the manual (www.php.net/nl2br)

bastien


>From: "Giff Hammar"
>To:
>Subject: [PHP-DB] Remove newlines from field
>Date: Mon, 20 Mar 2006 17:00:49 -0500
>
>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
>mailto: ghammar@certifiedparts.com
>V: 603.516.1707
>F: 603.516.1702
>M: 603.490.7163
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Remove newlines from field

am 20.03.2006 23:31:56 von Giff Hammar

------=_NextPart_000_00B3_01C64C44.2F839F00
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit

Thanks, Jeremy and Bastien. I just tried nl2br and it has the unfortunate
side effect of losing everything except the most recently added data when I
update the database. I think I need something like the 'local $/ = "\r\n"'
construct in perl...

Giff

_____

From: Jeremy Peterson [mailto:jeremy.peterson@moody.edu]
Sent: Monday, March 20, 2006 5:14 PM
To: Giff Hammar
Subject: Re: [PHP-DB] Remove newlines from field


Try nl2br.

http://php.net/nl2br

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/>
mailto: ghammar@certifiedparts.com
V: 603.516.1707
F: 603.516.1702
M: 603.490.7163




Jeremy Peterson, MACS
Automation Systems Administrator
Crowell Library
Moody Bible Institute
820 N. LaSalle Drive
Chicago, IL, 60610

Email: jpeterso@moody.edu
Phone: 312.329.8081
Fax: 312.329.8959


------=_NextPart_000_00B3_01C64C44.2F839F00--

Re: Remove newlines from field

am 20.03.2006 23:53:45 von Ludvig Ericson

Mind you Pearl programmers, what would that do?

On 3/20/06, Giff Hammar wrote:
> Thanks, Jeremy and Bastien. I just tried nl2br and it has the unfortunate
> side effect of losing everything except the most recently added data when=
I
> update the database. I think I need something like the 'local $/ =3D "\r\=
n"'
> construct in perl...
>
> Giff
>
> _____
>
> From: Jeremy Peterson [mailto:jeremy.peterson@moody.edu]
> Sent: Monday, March 20, 2006 5:14 PM
> To: Giff Hammar
> Subject: Re: [PHP-DB] Remove newlines from field
>
>
> Try nl2br.
>
> http://php.net/nl2br
>
> At 04:00 PM 3/20/2006, you wrote:
>
>
> I am using a PHP script to pull information from a FoxPro database via OD=
BC.
> 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 exist=
ing
> info and try to update the database. It fails with an "unrecognized comma=
nd"
> 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/>
> mailto: ghammar@certifiedparts.com
> V: 603.516.1707
> F: 603.516.1702
> M: 603.490.7163
>
>
>
>
> Jeremy Peterson, MACS
> Automation Systems Administrator
> Crowell Library
> Moody Bible Institute
> 820 N. LaSalle Drive
> Chicago, IL, 60610
>
> Email: jpeterso@moody.edu
> Phone: 312.329.8081
> Fax: 312.329.8959
>
>
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Remove newlines from field

am 21.03.2006 00:17:11 von Miles Thompson



>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/>
>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

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Remove newlines from field

am 21.03.2006 02:52:55 von Miles Thompson

At 07:17 PM 3/20/2006, Miles Thompson wrote:
>
>
>

Forgot to add that the writers work in WP 5.2 for Windows, because it has
an excellent indexing function which enables them to locate back stories v.
quickly.

That text is cut and pasted into an HTML textarea, which is saved to a
MySQL database. nl2br() is also applied to the text before saving. The idea
is to get straight HTML into the database.

For display the text is fetched, stripslash()'d and fed as an XML stream to
an HTMLText control in a Flash movie.

Quirks in how the movie displayed the text, resulted in some of the
constructs that had to be detected and removed. Same thing, occasionally,
in the textarea.

So this may not be the ideal solution, but it works for us.

Cheers - Miles


--
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

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Remove newlines from field

am 21.03.2006 13:57:53 von Giff Hammar

-----Original Message-----
From: Ludvig Ericson [mailto:ludvig.ericson@gmail.com]
Sent: Monday, March 20, 2006 5:54 PM
To: Giff Hammar
Cc: php-db@lists.php.net
Subject: Re: [PHP-DB] Remove newlines from field

Mind you Pearl programmers, what would that do?

[snip]

It changes the end of line delimiter to match the platform that you're on
(\r\n for Windows, \r for Mac and \n for Unix/Linux).

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Remove newlines from field

am 21.03.2006 16:15:34 von Giff Hammar

-----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



>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/>
>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

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php