/    Sign up×
Community /Pin to ProfileBookmark

spaces problem help

hey i just found out today that if i enter the word:

Hello World

then save it in the database..then later if i would output it, it would display

Hello World, i check the database it’s value is still Hello World but when it is outputed in html it becomes Hello World… same goes for pressing enter

Hello
World
is stored accurately in the database but outputted in the html as Hello World… how come? how do i overcome this obstacle if i want to output exactly the same value?? can someone help me thanks

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@chazzyMay 16.2006 — use nl2br to convert the new lines to html br's

as for the spacing, i don't see it. you'd have to replace each " " with "& nbsp;" but remove the space.
Copy linkTweet thisAlerts:
@DaiWelshMay 16.2006 — <snip>..stored accurately in the database but outputted in the html as Hello World... how come? how do i overcome this obstacle if i want to output exactly the same value?? can someone help me thanks[/QUOTE]

Are you sure it is output in the html wrong, or is it just displayed in a different way than you expect? The HTML spec says that more than one whitespace character in sequence are treated the same as a single whitespace character so you can put as many spaces, new lines, tabs etc. between two words as you like and they will still display with a single space visually.

If it looks right when you do View/Source then it is not a problem with your code per se, just the way HTMl is specced.

If so thenyou can either convert as suggested by above poster or you can use html <pre></pre> tag which will render whitespace as you perhaps expect.

HTH,

Dai
Copy linkTweet thisAlerts:
@NogDogMay 16.2006 — Another option might be to wrap the output in <pre>...</pre> tags if you want to preserve all white space ane newlines.
×

Success!

Help @JackOfBlades spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.23,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...