I've got the following issue with PHP and PostgreSQL. In a table I added the following value, mark the spaces.
Things: 10 POLI
When I read this out with PHP it will become
Things 10 POLI
My simpified code (for an ideal world without errors) is:
$query = "SELECT stuff, thing, planets FROM 42 WHERE answer = '-'";
$result = pg_query($connection, $query);
$resultTable = pg_fetch_all($result);
Then with
echo "Things: $result[stuff]";
My question is, which step eliminates all the white spaces? And how to get these spaces back? I know that most people want to remove them, I want to keep them.
that is not a PHP issue, but a HTML issue, becauyse if you output with echo, you do in fact generate HTML code.
The HTML specification defines, that multiple consecutive spaces get rendered as only one space.
If you want to avoid this, wrap a <pre>
tag around the string:
echo "<pre>Things: $result[stuff]</pre>";
That's because browser does not recognize more than one space, you can use this code to convert consective spaces to
(space understood by browser)
$str = str_replace(' ', ' ', $origText);
Or alternatively wrap your text in <pre>
tag if that suites your requirements as suggested in comments below.