php xml writing problem

  • Started
  • Last post
  • 8 Responses
  • section_014

    I'm using the dom xml class that comes with php 5 to write xml files from entered form data. I've sucessfully entered data, including data with html links and tags while testing.

    However, I'm having a problem with a blog article a co-worker is trying to publish.

    The article is just text and it's about 6 or 7 paragraphs long. It will not write to an xml file. Parts of it will though. For instance, I took one of the paragraphs and copied and pasted it 50 times in the entry field and it wrote no problem. Also, I entered the first few paragraphs and they wrote fine. However, when I try to paste the entire article in, it won't write. I thought maybe a quotation mark or comma was the culprit, but I did a test entry with every non alphanumeric character on the keyboard in conjunction with letters and it wrote fine. I checked the xml file and they were all properly converted to html friendly entities (ie. & instead of &).

    So, if the length of the article isn't to blame and it's not a character throwing things off, what is it?? This is unbelievably frustrating.

    Here's the code, but I don't think it's the problem since it works for other entries:

    // retrieve form data
    $title = $_POST['title'];
    $description = $_POST['content'];

    // get date info for naming files and adding link data
    $today = getdate();
    $link_data = $today['year'] . "_" . $today['mon'] . "_" . $today['mday'] . "_" . $today['hours'] . "_" . $today['minutes'] . "_" . $today['seconds'];

    // array that contains all the new item data
    $item = array(
    'title'=>$title,
    'content'=>$description,
    'link'=>$link_data
    );

    $url = $_SERVER['SERVER_NAME'] . "/welsh/catalog/blog.php?id=" . $item['link'];

    // Insert into database to query later on
    $sql = "INSERT INTO blog(year,month,day,hour,minute... VALUES(" . $today['year'] . "," . $today['mon'] . "," . $today['mday'] . "," . $today['hours'] . "," . $today['minutes'] . "," . $today['seconds'] . ",'" . $item['link'] . "')";
    mysql_query($sql);

    //create xml document
    $doc = new DOMdocument();
    $doc->formatOutput = true;

    $newEntry = $doc->createElement('item');
    $doc->appendChild($newEntry);

    $title = $doc->createElement('title');
    $title -> appendChild(
    $doc->createTextNode($item['titl...
    );
    $newEntry->appendChild($title);

    $link = $doc->createElement('link');
    $link -> appendChild(
    $doc->createTextNode($url)
    );
    $newEntry->appendChild($link);

    $desc = $doc->createElement('description...
    $desc -> appendChild(
    $doc->createTextNode($item['cont...
    );
    $newEntry->appendChild($desc);

    $doc->save("../blog/" . $item['link'] . ".xml");

  • acescence0

    where is the text coming from? word maybe? is it UTF-8? maybe there are invisible control characters you're not seeing? do you have all error reporting enabled in php?

  • heavyt0

    i concur.
    usually it is a weird line feed or return from a Word file that causes shizz like that.
    I would make sure you are displaying errors. ini_set('display_errors','On');
    that will give you a better hint, if nothing else

  • rounce0

    Might it be that the field length in the table you're pulling this from isn't long enough?

  • section_0140

    you're both right.

    The colleague's email program or word processor software was sending some me single quotes and double quotes in a format it didn't like. I narrowed the problem down to 2 paragraphs and then deleted and replaced all single and double quotes. It went through like a charm after that. The style of the characters were visibly different compared to the ones I entered. Yes, I have full error reporting on.

    I'm gonna go smack the shit out of him and tell him to write the rest of his entries in notepad.

    Thanks!

  • heavyt0

    yeah, Word can be a real bugger.
    I have found luck using the accept-charset attribute in the CMS form. It usually cleans up these errant chars before they go into the db and cause further issues.

  • falcadia0

    I deal with the problem on a daily bases

  • acescence0

    check out TinyMCE, it's a javascript editor that you can put on a text field, you can filter out all the bad stuff with it.

  • acescence0