white spaces in uploaded html file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matthias Langbein

    #1

    white spaces in uploaded html file

    Hi all,
    on one of my sites I want to give the user the possibility to upload a
    html file where I want to extract all that is within the <body>-tags.
    The upload works fine:

    <form id="uploadform " action="index.p hp" method="post"
    enctype="multip art/form-data">
    <input type="file" name="Datei" size="30"/>
    <input type="submit"/>
    </form>

    Then I want to parse the uploaded file with:

    <?php
    if (isset($_FILES['Datei']) and !$_FILES['Datei']['error']) {
    $buffer = file_get_Conten ts($_FILES['Datei']['tmp_name']);
    echo "body: ".$buffer." \n";
    }
    ?>

    I get a weird result:
    body: ÿþ< h t m l < h e a d < t i t l e < / t i t l e .....
    So there seem to be some white spaces between every character.

    And then there is no way to find the <body>-tag.
    Neither
    echo "sub: ".strpos($buffe r, "< b o d y")."\n";
    nor
    echo "sub: ".strpos($buffe r, "<body")."\ n";
    works. Both show no result.

    Can anybody explain me this? How can I parse the file to extract
    everything which is within the <body>-Tags (possibly without the white
    spaces)?

    Thanks a lot,
    Langi

  • Andy Hassall

    #2
    Re: white spaces in uploaded html file

    On Sun, 23 Jul 2006 01:16:49 +0200, Matthias Langbein
    <matthias_langb ein@web.dewrote :
    >I get a weird result:
    >body: ÿþ< h t m l < h e a d < t i t l e < / t i t l e .....
    >So there seem to be some white spaces between every character.
    They're not spaces; that's UTF-16 encoded (with a leading BOM character).

    What encoding is the original page in? What was the file you uploaded edited
    with? You may also want to look at the accept-charset attribute of the <form>
    element.

    --
    Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
    http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

    Comment

    • Matthias Langbein

      #3
      Re: white spaces in uploaded html file

      Thanks, that was the problem. I saved the file with UTF-8 and it
      worked.

      Are you shure that the accept-charset attribute works? I had set it to
      UTF-8 or UTF-16 and uploaded a file in UTF-8 and UTF-16, and the
      upload worked in all four cases. So I don't really thing that this
      contraint is implemented.

      Unfortunatelly I have to accept UTF-8 and UTF-16 encoded files. Is
      there a way to convert the stream to UTF-8

      Thanks for your help!!

      On Sun, 23 Jul 2006 00:50:15 +0100, Andy Hassall <andy@andyh.co. uk>
      wrote:
      >On Sun, 23 Jul 2006 01:16:49 +0200, Matthias Langbein
      ><matthias_lang bein@web.dewrot e:
      >
      >>I get a weird result:
      >>body: ÿþ< h t m l < h e a d < t i t l e < / t i t l e .....
      >>So there seem to be some white spaces between every character.
      >
      They're not spaces; that's UTF-16 encoded (with a leading BOM character).
      >
      What encoding is the original page in? What was the file you uploaded edited
      >with? You may also want to look at the accept-charset attribute of the <form>
      >element.

      Comment

      • Kimmo Laine

        #4
        Re: white spaces in uploaded html file

        spam@outolempi. net || Gedoon-S @ IRCnet || rot13(xvzzb@bhg byrzcv.arg)
        "Matthias Langbein" <matthias_langb ein@web.dewrote in message
        news:nre6c2tmdt su6lj11j7q2v54j lnpt9rce2@4ax.c om...
        Thanks, that was the problem. I saved the file with UTF-8 and it
        worked.
        >
        Are you shure that the accept-charset attribute works? I had set it to
        UTF-8 or UTF-16 and uploaded a file in UTF-8 and UTF-16, and the
        upload worked in all four cases. So I don't really thing that this
        contraint is implemented.
        >
        Unfortunatelly I have to accept UTF-8 and UTF-16 encoded files. Is
        there a way to convert the stream to UTF-8



        $file = mb_convert_enco ding($file, 'UTF-8', 'auto');

        --
        "Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
        http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis


        Comment

        Working...