Forum Moderators: coopster

Message Too Old, No Replies

strange characters in text box

lots of spaces out of nowhere

         

omoutop

9:23 am on Jun 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hello all.
In one application I have some text fields in 5 languages(english, italian, german, french and greek).
The text i save into db has max length 600 characters (checked by javascript while typing), the db field property is Longtext.

Now the strange part: when i show the saved text into a form, it shows "................................."
in front of text (replenish . with space between "") in 3 of the 5 fields (the rest are ok). While in application the text appears correctly, in administration pages, the extra spaces prevents me from inserting a full 600 character length text.

I have echoed the $_POST data of the form, it's ok.
I have trimed the $_POST data of the form, no result.
I have echoed the data outside form field, all ok.
Try using trim($str,"\x7f..\xff\x0..\x1f"), no result.
Try using trim($str,"\n\t\r\h\v\0\x0B"), no reuslt.

What can be wrong and how can I fix it?.

Habtom

9:38 am on Jun 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Using a textbox or textarea? If textarea the spaces could still be there in between the tags <textarea></textarea>

Habtom

vincevincevince

9:40 am on Jun 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I wonder if they really are spaces. Try using ord() and finding out the character codes for each character in the string:

for ($a=0;$a<len($string);$a++) print "Letter $a is ".ord($string[$a])."<br>";

omoutop

10:04 am on Jun 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



@Habtom: no i have doublechecked code - no spaces between tags in form.

@vincevincevince: ruuning your code i got "Letter 0 is 32"
Strange as it sees only 1 character. Can you tell me what that character is? Because i dont think its a space

vincevincevince

10:08 am on Jun 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Can you paste here the line of your administrator script which does the output of the field into the HTML? Exactly as in your source, if possible.

As I remember, 32 is a standard space. If there was only letter 0 in there, then there was one space in the string, and nothing else - not even tabs or linebreaks. That's why I am now thinking about your output code.

omoutop

10:24 am on Jun 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



When i get data from db I have:
$h_german_small_text = stripslashes($hotrec['german_small_text']);

inside form i have:


<td>Small Text <input readonly type=text name=ger size=3 maxlength=3 value="600"> chars left<br>
<textarea rows="5" name="german_small_text" cols="55" onKeyDown="textCounter(this.form.german_small_text,this.form.ger,600);" onKeyUp="textCounter(this.form.german_small_text,this.form.ger,600);">
<? echo trim($h_german_small_text);?></textarea>
</td>

vincevincevince

10:28 am on Jun 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First point - remove the linebreak before the <? within your <textarea>... that is a character before you start. If you have any tabs, spaces, etc. in that place (WebmasterWorld strips them) then remove them too.

You need to have:

...><? echo trim($h_german_small_text);?></textarea>

Next - try to find out about your page encoding and your database encoding. If you change your page encoding in your browser to UTF-8 or something else, does the problem go away? If you are sending out your HTML in multibyte encoding, and your Database results in singlebyte encoding, it can cause problems like you complain of - same goes with the reverse.

omoutop

11:52 am on Jun 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



well the proble appers in only 3 texareas out of 86 total textfields/textareas - all written similar as previous example.

And the problem still appeas in UTF8 encoding.
the data are saved correclty in db - appear correclty in front-end application.
only problem is the 3 out of 5 languages.

funny thing... i even try to use a loop to generate the textarea (so as to check if i have done something wrong (typo for example) and thus having problem in all 5 languages) - 2 languages worked correct, 3 do not.

example:
$lang_array = array("english", "greek", "french", "german", "italian");

foreach ($lang_array as $language)
{
// show <td>....</td>
}

Double/triple checked the db fields - all 5 are Longtext, Not Null.

Run repair on table in db
Execute script with error reporting set to E_ALL - nothig showed up (script is up and running for 6-7 months)
echoed every step of script to make sure all info/data are the same in every step - Yes they are the same as i typed them in textarea.

I know it it not a serious problem, I know that the solution must be an obvious one, but havent figured anyhting out.

Oh well... it must be one of those days.