ID:               43549
 User updated by:  mariusads at helpedia dot com
 Reported By:      mariusads at helpedia dot com
 Status:           Open
 Bug Type:         Strings related
 Operating System: Redhat?,  Linux
 PHP Version:      5.2.5
 New Comment:

small update: problem is solved kind of) if I don't specify 'UTF-8' or
if I use htmlspecialchars without 'UTF-8' (though the document looks
different than before, but I guess I'll just have to replace those ascii
characters with images, probably).


Previous Comments:
------------------------------------------------------------------------

[2007-12-11 13:23:52] mariusads at helpedia dot com

The example you gave me does work but my issue has nothing to do with
receiving data in textarea or input boxes.

The page here:
hxxp://www.tgdb.net/pc/faq/5845/Diablo-page1.html

tries to open a text document from a certain location on the drive
which was previously uploaded by the user in a zip file.

If I change the example you gave me to read the text from a file:

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<pre>
<?php
$text = file_get_contents('a.txt');
  
var_dump($text);
var_dump(htmlentities($text,ENT_QUOTES,'UTF-8'));

?>
</pre>
<form name="A" method="post">
<textarea name="text"></textarea>
<input name="sub" type="submit" value="submit"/>
</form>
</body></html>

which basically gets the text from the text file, htmlentities no
longer works as I expected it. I guess with your example, the browser
corrects the text pasted in the form before sending it to the script.

Almost all files I have are like the NFO files in scene releases, they
contain drawings made with ASCII characters, but I need them escaped
because the whole page is sent as UTF-8. They don't have multibyte stuff
on purpose and they're not corrupted or something like that.

It's also not feasible to tell the user to paste them in a text area in
a form, almost all submitted content is sent in a ZIP file and my
scripts extract the text file. Some files are also about 4-600KB in size
(walkthroughs) so using text area is out of the question.

I'm surprised to see that htmlentities returns a blank string and I
honestly don't know how to fix this so any help would be great.
Shouldn't it return the string up until the point where multibyte
characters are, whatever that means?

Could my problem be solved if I don't use the charset argument or if I
use htmlspecialchars? (i'll test...) Or is there another solution to my
predicament?

Thank you again for replying to my questions. I had bad experiences in
the past where other people just ignored my messages after replying with
"works for me". I really appreciate it.

------------------------------------------------------------------------

[2007-12-11 12:28:40] [EMAIL PROTECTED]

You never specified the charset for the page. This works fine:

<html>
<head> 
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<pre>
<?php
$text = isset($_REQUEST['text']) ? $_REQUEST['text'] : '';
  
var_dump($text);
var_dump(htmlentities($text,ENT_QUOTES,'UTF-8'));

?>
</pre>
<form name="A" method="post">
<textarea name="text"></textarea>
<input name="sub" type="submit" value="submit"/>
</form>
</body></html>


------------------------------------------------------------------------

[2007-12-10 11:45:38] mariusads at helpedia dot com

Just downloaded on my computer (Windows 2003, PHP 5.2.5 from website)
and the same problem occurs.

For example this one works: 

hxtp://devtgdb.definethis.org:90/pc/faq/5842/Diablo-page1.html

but this one doesn't:

hxtp://devtgdb.definethis.org:90/pc/faq/5845/Diablo-page1.html

The source code is identical, only difference is ads are disabled from
site config.
Also, if the links don't work, sorry, you may read this while I'm
sleeping and my computer is turned off. Otherwise, it's cable
4mbps/512kbps so they should work.

(again, please replace hxtp with http)

------------------------------------------------------------------------

[2007-12-10 11:24:16] mariusads at helpedia dot com

Here are several pages that show this problem with htmlentities:

hxtp://www.tgdb.net/pc/cheats/19556/18_Wheels_of_Steel_Convoy-page1.html
hxtp://www.tgdb.net/pc/faq/5845/Diablo-page1.html

The content on the second link worked fine up until the PHP version was
upgraded.

This page and lots of other work:

hxtp://www.tgdb.net/pc/faq/5841/Diablo-page1.html

So it's not a badly coded script in the sense that it worked as I
planned.

You can see the text right before it's being sent to htmlentities in
all pages in a html comment, you just have to view the source (with the
only difference that I've replaced '--' with '==' as -- is not allowed
in comments.

When I reported the problem to the hosting company, I have uploaded the
test script written in the first post on two of their servers and a
server from Dreamhost.
PHP 5.2.5 hxtp://www.helpedia.com/test2.php
PHP 5.2.5 hxtp://www.tgdb.net/test2.php
PHP 5.2.2 hxtp://www.definethis.org/test2.php

I've opened the file a.txt in Firefox, pressed Ctrl+A to select all
text, copied to Clipboard and pasted it to the form. Result is an empty
string on PHP 5.2.5 and the correct string on PHP 5.2.2. Correct result
also on my work computer with PHP 5.2.4

I didn't manage to download 5.2.5 on my work computer and test it, so I
guess it could be a bad build on the hosting company's servers. Will try
in the following hour.

(replace hxtp with http, this page thinks I'm spamming)

------------------------------------------------------------------------

[2007-12-10 09:32:57] [EMAIL PROTECTED]

Works fine for me. Are you sure you have everything as utf-8..ie. the
page you're sending the form from has content-type set to utf-8 ?

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/43549

-- 
Edit this bug report at http://bugs.php.net/?id=43549&edit=1

Reply via email to