You are here:  » Help - Invalid Character


Help - Invalid Character

Submitted by dtbcinci on Fri, 2007-08-10 00:13 in

David or anyone,

I hope that you can come to my aid once again.

You gave me the solution for the one problem with &, but now I can't get a lot of the RSS feeds to open because I keep getting
"An invalid character was found in text content" example http://www.vids411.com/parser/svnaturea.php.

What can I do about this!! It is driving me nuts!!

Any help is appreciated.

David

Submitted by support on Fri, 2007-08-10 02:38

Hi David,

This looks like almost the same problem as before, but a different field and a different character. This time, in the TITLE field, the particular value that breaks your example URL contains the characters, which also need to be entity encoded within XML. This time, also change:

    print "<title>".$video["TITLE"]."</title>";

to:

    print "<title>".htmlentities($video["TITLE"])."</title>";

Hope this helps,
Cheers,
David.

Submitted by dtbcinci on Fri, 2007-08-10 14:59

David,

I placed the code into the example as you stated and I am still getting an error.

Example: http://www.vids411.com/parser/newtest5.php

Sorry for driving you nuts but without your help I am stuck.

Thanks in advance,
David

Submitted by support on Fri, 2007-08-10 15:11

Hi David,

My apologies - htmlentities is actually overkill in this scenario and is generating entities that are not actually valid in plain XML. The solution is to write a simple xmlentities() function and use that instead. To do this, add the following function to the top of your script:

  function xmlentities($text)
  {
    $search = array('&','<','>','"','\'');
    $replace = array('&amp;','&lt;','&gt;','&quot;','&apos;');
    $text = str_replace($search,$replace,$text);
    return $text;
  }

Then, wherever you have added htmlentities (in the 2 cases above), replace this with xmlentities instead. That should do the trick!

Hope this helps,
Cheers,
David.

Submitted by dtbcinci on Fri, 2007-08-10 21:18

David,

Thank you very much for you help.

I have the new code loaded and it appears to be working great on feeds now that broke before.

Thanks a million,

David