SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru D-flyer's Avatar
    Join Date
    Jan 2001
    Location
    Near a computer
    Posts
    782
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How can i generate special characters thru php to .xml???

    good morning,

    i am making a simply guestbook using flash 5 as front-end and php/xml as the back-end.

    I got it to work except when a users input contains special characters like alt+....
    Then the php code (see below) generate a invalid xml file. How to solve this??????
    PHP Code:
    <?PHP

    if ($command=="sign"){

        
    /*check if the guestbook has been signed*/    
        
    if ($naam!="" && $words!=""){

            
    $existing_entries file('guest.xml','r');//read the file in array.

            
    foreach($existing_entries as $entry)//check each element.
            
    {
                    if(! 
    ereg('</guestbook>',$entry) )//if file has /guestbook dont read it unless keep reading in $new_entries.
                
    {
                        
    $new_entries[] = $entry;
        }
    }
    //$new_entries has all the contents of old file except </guestbook> .
    //so now write in new entries
    $new_entries[] ="\t<message>\n"
    $new_entries[]="\t\t<naam>".$naam."</naam>\n"
    $new_entries[]="\t\t<email>".$email."</email>\n"
    $new_entries[]="\t\t<words>".$words."</words>\n"
    $new_entries[]="\t</message>\n"

    $new_entries[]="\t</guestbook>\n";  //add /guestbook tag.

    $data join("",$new_entries);//join all the lines by nothing. \n are already there.

    $fp fopen('guest.xml','w');//open guest.xml file,
    fwrite($fp,$data);//write in data.
    fclose($fp);//close the handle.
    }
        echo(
    "done=1");
    }

    ?>
    Thx in advance
    D-flyer
    (with special thx to jdk)

  2. #2
    SitePoint Guru D-flyer's Avatar
    Join Date
    Jan 2001
    Location
    Near a computer
    Posts
    782
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have an answer:
    encoding my xml file with ISO-8859-1 seems to do the trick

    Grtz, D-flyer


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •