PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Is there a way to get extra spaces, in text, in a textarea to insert into a database(MySQL) and retrieve it? I'm looking for something that sort of works like nl2br() for spaces.
I was *attempting* to build a forum for my game and it didn't work to well, but in the process i discovered how to add a BBcode type of system to it using eregi_replace() and another thing i noted was the fact that when someone hits enter in the new topic page, it wasn't turning out on the forum page. So i did another eregi_replace() this time instead of inserting smilies or substituting for html code i simply inserted spaces like so:
// inserting br's into the spaces for the messegebody area
$Pattern = "її]]її]]";
$Replace = "<br>";
$Arrayї"MessegeBody"] = eregi_replace($Pattern, $Replace, $Arrayї"MessegeBody"]);
Note: 2 [[:space:]]'s are needed to tell the differene between a line and a word-word space.
<textarea rows="4" name="message" cols="69"><?=$text?></textarea>
$text="What do_____ you want to do today?"
I can't even show you an example of the text because even this site trims out the extra spaces. The under line represents the Extra spaces.
Actually, its just like this sites textarea! On preview, the form textarea is repopulated with the extra spaces, so $_POST holds on to it some how, but when displayed in html or sent to a database, it's lost.
Should I try to use &-nbsp; ? I thought there might be a function like trim() but in reverse or really notrim() . htmlspecialchar() doen't seem to work for spaces. Any Ideas?
...will show actual spaces in everthing phpinfo(), Mysql, and textareas.
( I used "&-nbsp" for posts because without the "-" &-nbsp just displays a space. )
(Come to think of it, that's probably what you did. It's 8AM on Sunday and I'm still a little slow.)
That will work but is a non-breaking space therefore according to the browser it is just one long word therefore if someone posted a long enough thread then the screen would just get stretched horizontally.
EDIT: To make what I said more clear imaginge that is really an invisible _ then you would get this:
(where "-" is a space (easier to count than"__"))
(&_nbsp is just to allow display of the "no break space code")
This will allow the line breaks and will allow odd and even numbers of
spaces to be displayed. The only draw back is that it's possible to
add "&_nbsp" to the begining of a word causing the
New line to misalign a space....as so...<---