Jump to content

TEXTAREA - displaying a 'space character'


murfitUK

Recommended Posts

As usual, my question is a bit vague but I'll try and explain as best I can! Wonder if this would better go in the php forum?I am using a textarea in a form which I want to populate with info from a database. This all works fine:print "<textarea name='display' cols='40' rows='6'>" . $codeSnippet . "</textarea>";The codeSnippet will have things like "This is <b>bold</b> text" which I want displayed exactly like that. I don't have to worry about stripping slashes and cleaning the data because the database is read only.The problem is that sometimes it is not clear that there is a space if it is at the end of the line. This is particularly the case with tags like <br /> where there is a space between the <br and the />. What I would like to do is display the tiny little dot in place of the spaces - you know in Word you can switch on the non-printing characters and it shows the spaces, new lines, carriage returns etc (although I'm only interested in the spaces).Is there a (quick and easy) way to do this?

Link to comment
Share on other sites

 

add that where the space should be. It is called a non-breaking space.

Where do i find that lesson? url?. . . . . . . . . . . . . . .You could use <pre></pre> tags.
Where do i find that lesson? url?. . . . . . . . . . . . . . .You could use <pre></pre> tags.(remove)
u could use <pre></pre> tags . . .
Link to comment
Share on other sites

No, if you g to word and hit the paragraph button it will change all spaces into periods. Not pre, that just doesnt change spaces to nothing. If you want to do it using php use this:

$codeSnippet = str_replace(" ", ".", $codeSnippet);print "<textarea name='display' cols='40' rows='6'>" . $codeSnippet . "</textarea>";

and it will be done!

Link to comment
Share on other sites

Thanks everyone - using the str_replace works the best.I also found out that the character I wanted is called "middle dot" and has the code & m i d d o t or & # 1 8 3 ;. (Sorry - had to put spaces in between the characters as previewed and found that the codes had been replaced with the little dot!)The function

str_replace(" ", & # 1 8 3; , $codeSnippet)

with no quote marks around the & # 1 8 3 ;gives exactly what I need.This·is·what·it·looks·like·with·a·little·middle·dot.HOWEVER...... (life is never easy)Now that there are no spaces it treats it as a big long line of text with no natural breaks for it to start on a new line. This results in a horizontal scrollbar, with just one line of text at the top of the box.I think I will have to count the characters and stick a <br /> after every 40 or so, although not sure if it will work in a textarea. Will soon find out.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...