[multibyte-safe htmlentities()]

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thorsten Ottosen

    #1

    [multibyte-safe htmlentities()]

    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_enco ding( $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
  • Chung Leong

    #2
    Re: [multibyte-safe htmlentities()]

    Try converting the text from UTF-16 to UTF-8, running the result thru
    htmlentities, then converting it back to UTF-16.

    Comment

    • Stephen Kay

      #3
      Problem with multi-byte characters with curl


      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
      ^^^^^^^


      Comment

      • Stephen Kay

        #4
        Re: Problem with multi-byte characters with curl

        in article C0475AB8.59ECA% sk@karma-lab.nospam.com, Stephen Kay at
        sk@karma-lab.nospam.com wrote on 3/22/06 7:52 PM:
        [color=blue]
        >
        > 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.[/color]


        Nevermind, I found the answer:

        Need to use mb_convert_enco ding() on the results of curl.

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


        Comment

        • R. Rajesh Jeba Anbiah

          #5
          Re: Problem with multi-byte characters with curl

          Stephen Kay wrote:[color=blue]
          > in article C0475AB8.59ECA% sk@karma-lab.nospam.com, Stephen Kay at
          > sk@karma-lab.nospam.com wrote on 3/22/06 7:52 PM:[/color]
          <snip>[color=blue]
          > Nevermind, I found the answer:
          >
          > Need to use mb_convert_enco ding() on the results of curl.[/color]

          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/

          Comment

          • Stephen Kay

            #6
            Re: Problem with multi-byte characters with curl

            in article 1143093823.5693 21.89030@z34g20 00...legro ups.com, R. Rajesh
            Jeba Anbiah at ng4rrjanbiah@re diffmail.com wrote on 3/23/06 1:03 AM:
            [color=blue]
            > Stephen Kay wrote:[color=green]
            >> in article C0475AB8.59ECA% sk@karma-lab.nospam.com, Stephen Kay at
            >> sk@karma-lab.nospam.com wrote on 3/22/06 7:52 PM:[/color]
            > <snip>[color=green]
            >> Nevermind, I found the answer:
            >>
            >> Need to use mb_convert_enco ding() on the results of curl.[/color]
            >
            > IIRC, you don't have to if your PHP file is in UTF8[/color]

            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_HTTPHEA DER, array('Accept-Charset: UTF-8;'));


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


            Comment

            • Stephen Kay

              #7
              What does &quot;Call to a member function on a non-object&quot; mean?

              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
              ^^^^^^^


              Comment

              • Jerry Stuckle

                #8
                Re: What does &quot;Call to a member function on a non-object&quot; mean?

                Stephen Kay wrote:[color=blue]
                > 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.[/color]

                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.
                jstucklex@attgl obal.net
                =============== ===

                Comment

                • Tony Marston

                  #9
                  Re: What does &quot;Call to a member function on a non-object&quot; mean?

                  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

                  This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL




                  "Stephen Kay" <sk@karma-lab.nospam.com> wrote in message
                  news:C0485985.5 A1BB%sk@karma-lab.nospam.com. ..[color=blue]
                  > 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
                  > ^^^^^^^
                  >
                  >[/color]


                  Comment

                  • Stephen Kay

                    #10
                    Re: What does &quot;Call to a member function on a non-object&quot; mean?

                    in article e00cln$l81$1$83 00dec7@news.dem on.co.uk, Tony Marston at
                    tony@NOSPAM.dem on.co.uk wrote on 3/24/06 4:03 AM:
                    [color=blue]
                    > 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?[/color]

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

                    Stephen

                    Comment

                    • Thorsten Ottosen

                      #11
                      Re: [multibyte-safe htmlentities()]

                      Chung Leong wrote:[color=blue]
                      > Try converting the text from UTF-16 to UTF-8, running the result thru
                      > htmlentities, then converting it back to UTF-16.
                      >[/color]

                      I couldn't get that to work either.


                      D*** :-)

                      -Thorsten

                      Comment

                      Working...