Inserting spaces

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
frankpmjr
Forum Commoner
Posts: 26
Joined: Wed Sep 15, 2004 9:13 am

Inserting spaces

Post by frankpmjr »

How do I keep extra spaces from being stripped when I send a paragraph to a MySQL db and then display it later?
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

They shoudn't be stripped unless you explicitly do it AFAIK.
frankpmjr
Forum Commoner
Posts: 26
Joined: Wed Sep 15, 2004 9:13 am

Post by frankpmjr »

AFAIK
Sorry what does that mean? I am not using the trim function or anything just:

Code: Select all

$text = nl2br($_POSTї'text']);
                echo $text;
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

just as newlines aren't showed in html , spaces aren't either.

for newlines you can use nl2br... spaces you should display as  

[php_man]htmlentities[/php_man] doesn't seem to replace spaces by   so i suggest you

Code: Select all

$string = preg_replace("/\s/", " ", $string);
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

As Far As I Know - AFAIK :)
frankpmjr
Forum Commoner
Posts: 26
Joined: Wed Sep 15, 2004 9:13 am

Post by frankpmjr »

This doesn't seem to be working, here is the code I used:

Code: Select all

$text = nl2br($_POSTї'text']);
$revised_text = preg_replace("/\s/", " ", $text);
Then later I used

Code: Select all

echo $revised_text
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

must something in your code because:

Code: Select all

$string = "ik ben      veel ' spaties ver";
$string = preg_replace("/\s/", " ", $string);
echo $string;
outputs:

Code: Select all

ik ben      veel ' spaties ver
Post Reply