Page 1 of 1

Inserting spaces

Posted: Wed Dec 08, 2004 7:36 am
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?

Posted: Wed Dec 08, 2004 7:41 am
by protokol
They shoudn't be stripped unless you explicitly do it AFAIK.

Posted: Wed Dec 08, 2004 7:47 am
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;

Posted: Wed Dec 08, 2004 8:09 am
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);

Posted: Wed Dec 08, 2004 8:41 am
by Maugrim_The_Reaper
As Far As I Know - AFAIK :)

Posted: Wed Dec 08, 2004 9:20 am
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

Posted: Wed Dec 08, 2004 3:58 pm
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