Minase Posted August 18, 2008 Share Posted August 18, 2008 i was wondering how i can allow php to echo multiple spaces like $text = " Just a simple text"; the normal echo will output just 1 space,how i can do to allow more than 1 space?thanks Quote Link to comment Share on other sites More sharing options...
obsidian Posted August 18, 2008 Share Posted August 18, 2008 It really depends on what the type of your output is. If you are echoing to a plain text file, what you have will reflect the spaces in the output. On the other hand, if it is in HTML, you need to echo out the HTML entity for spaces: <?php echo " Just a simple text"; ?> Quote Link to comment Share on other sites More sharing options...
effigy Posted August 18, 2008 Share Posted August 18, 2008 You may find str_repeat helpful for this also. Quote Link to comment Share on other sites More sharing options...
Minase Posted August 18, 2008 Author Share Posted August 18, 2008 str_repeat isnt usefull for this thanks anyway i do get the data from a mysql DB and echo in HTML users hae a textarea and they input a description there.after that the index page will echo it,but if they put multiple spaces,in db they will exist,but at echo they disapear. i cant use in db,cause that value will be changed when users want,and i dont want to do a replace everytime Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 18, 2008 Share Posted August 18, 2008 <?php $text = " Just a simple text"; $text = str_replace(' ', '$nbsp;', $text); echo $text; //Output: "$nbsp;$nbsp;$nbsp;$nbsp;$nbsp;Just a simple text" ?> But, you might want to consider just using PRE tags as they will also preserve line-breaks and possibly other problem characters as well. Quote Link to comment Share on other sites More sharing options...
obsidian Posted August 18, 2008 Share Posted August 18, 2008 i cant use in db,cause that value will be changed when users want,and i dont want to do a replace everytime First off, a question: why not? When you echo HTML entities into a textarea, they are interpreted, so you should be fine with storing them as that. Secondly, though, you shouldn't do any display parsing (htmlentities and such) on INSERT into database, only when you retrieve it for display. When you insert, you should only worry about data escaping and protecting against SQL injection. Then, when you output that data, you can parse or modify it as needed for the environment in which you are working. Quote Link to comment Share on other sites More sharing options...
Minase Posted August 19, 2008 Author Share Posted August 19, 2008 thank you mjdamato your solution did help me (did not want to use str_replace,but it is the best solution) btw about input,i dont mind im 99% sure that the scripts are secured.thank you all Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.