By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,018 Members | 870 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,018 IT Pros & Developers. It's quick & easy.

[multibyte-safe htmlentities()]

P: n/a
Hi,

I'm trying to escape html before its saved in a database.

I tried

$text = htmlentities( $reader->value );

but that don't work for e.g. japanese characters.

I then tried

$text = mb_convert_encoding( $text, 'HTML-ENTITIES', 'UTF-16' );

because the text-file is encode in UTF-16.

But that in particular doesn't work. If I specify 'UTF-8'
the text looks normal, but nothing is escaped så html tags still
appears as tags.

can anyone suggest what to do?

Thanks

-Thorsten
Mar 22 '06 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Try converting the text from UTF-16 to UTF-8, running the result thru
htmlentities, then converting it back to UTF-16.

Mar 23 '06 #2

P: n/a

I am writing some php functions to run pages of my web site through
altavista's babelfish language translation services.

It works, kind of, but I have run into a problem with multi-byte
international characters.

If I call the desired URL query string directly by typing it into a browser,
it returns a doc, showing in the header:

http-equiv="content-type" content="text/html; charset=UTF-8

and properly displays the additional international characters.

If I call the exact same URL from inside my php code, using curl, the
resulting document appears to have the same UTF-8 encoding in the header,
yet the international characters are lost. I just get ? instead.

Any ideas?

--
Stephen Kay
Karma-Lab sk@karma-lab.NOSPAM.com
^^^^^^^
Mar 23 '06 #3

P: n/a
in article C0***************@karma-lab.nospam.com, Stephen Kay at
sk@karma-lab.nospam.com wrote on 3/22/06 7:52 PM:

I am writing some php functions to run pages of my web site through
altavista's babelfish language translation services.

It works, kind of, but I have run into a problem with multi-byte
international characters.

If I call the desired URL query string directly by typing it into a browser,
it returns a doc, showing in the header:

http-equiv="content-type" content="text/html; charset=UTF-8

and properly displays the additional international characters.

If I call the exact same URL from inside my php code, using curl, the
resulting document appears to have the same UTF-8 encoding in the header,
yet the international characters are lost. I just get ? instead.

Nevermind, I found the answer:

Need to use mb_convert_encoding() on the results of curl.

--
Stephen Kay
Karma-Lab sk@karma-lab.NOSPAM.com
^^^^^^^
Mar 23 '06 #4

P: n/a
Stephen Kay wrote:
in article C0***************@karma-lab.nospam.com, Stephen Kay at
sk@karma-lab.nospam.com wrote on 3/22/06 7:52 PM: <snip> Nevermind, I found the answer:

Need to use mb_convert_encoding() on the results of curl.


IIRC, you don't have to if your PHP file is in UTF8

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Mar 23 '06 #5

P: n/a
in article 11*********************@z34g2000cwc.googlegroups.c om, R. Rajesh
Jeba Anbiah at ng**********@rediffmail.com wrote on 3/23/06 1:03 AM:
Stephen Kay wrote:
in article C0***************@karma-lab.nospam.com, Stephen Kay at
sk@karma-lab.nospam.com wrote on 3/22/06 7:52 PM:

<snip>
Nevermind, I found the answer:

Need to use mb_convert_encoding() on the results of curl.


IIRC, you don't have to if your PHP file is in UTF8


This turned out to be a temporary fix. What really fixed it (for some
reason) was doing this to the curl session:

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Charset: UTF-8;'));
--
Stephen Kay
Karma-Lab sk@karma-lab.NOSPAM.com
^^^^^^^
Mar 23 '06 #6

P: n/a
Getting an error like this, when trying to call a function in another php
module from a different one:

Fatal error: Call to a member function on a non-object in
/home/mysite/public_html/forumtr/admin/functions.php

Thanks for any info.

--
Stephen Kay
Karma-Lab sk@karma-lab.NOSPAM.com
^^^^^^^
Mar 23 '06 #7

P: n/a
Stephen Kay wrote:
Getting an error like this, when trying to call a function in another php
module from a different one:

Fatal error: Call to a member function on a non-object in
/home/mysite/public_html/forumtr/admin/functions.php

Thanks for any info.


Sorry, Stephen, my crystal ball has been recalled by the factory. So I have no
idea what your code is.

Post some of the failing code and we might be able to help.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Mar 24 '06 #8

P: n/a
This is because you are doing something like
$result = $object->function($arg);
and $object is not an actual object. Perhaps you have not initialised it
yet, or miss-spelled it?

--
Tony Marston

http://www.tonymarston.net

"Stephen Kay" <sk@karma-lab.nospam.com> wrote in message
news:C0***************@karma-lab.nospam.com...
Getting an error like this, when trying to call a function in another php
module from a different one:

Fatal error: Call to a member function on a non-object in
/home/mysite/public_html/forumtr/admin/functions.php

Thanks for any info.

--
Stephen Kay
Karma-Lab sk@karma-lab.NOSPAM.com
^^^^^^^

Mar 24 '06 #9

P: n/a
in article e0*******************@news.demon.co.uk, Tony Marston at
to**@NOSPAM.demon.co.uk wrote on 3/24/06 4:03 AM:
This is because you are doing something like
$result = $object->function($arg);
and $object is not an actual object. Perhaps you have not initialised it
yet, or miss-spelled it?


Thanks for the info. It seems there was an uninitialized object in an
included file.

Stephen

Mar 24 '06 #10

P: n/a
Chung Leong wrote:
Try converting the text from UTF-16 to UTF-8, running the result thru
htmlentities, then converting it back to UTF-16.


I couldn't get that to work either.
D*** :-)

-Thorsten

Mar 27 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.