Echo PHP character spaces from MySQL

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
sleepydad
Forum Commoner
Posts: 75
Joined: Thu Feb 21, 2008 2:16 pm

Echo PHP character spaces from MySQL

Post by sleepydad »

I am inserting data into MySQL using:

Code: Select all

$query="insert into `` values ('','','')";
$result=$db->query($query);
Works fine. Is some instances, the data that I'm entering will have odd character spaces ie:

hello
  wo

 r
  l
   d

I've designated the row for this in MySQL to be TEXT, and when the record is added it shows exactly as I've demonstrated when viewing in phpmyadmin. When I echo it out using:

Code: Select all

echo $row[''];
... my output is all flush left. I've tried str_replace('',' ',$string), but that didn't work. I've tried inserting the record using htmlspecialchars - didn't work. I've echoed using nl2br - nope.

Suggestions??

Thanks -
sleepydad
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Echo PHP character spaces from MySQL

Post by Christopher »

It seems like something in your code is converting spaces to the meta character   This is probably done for outputting in HTML, but should not be done for the database.
(#10850)
Post Reply