0

The XML I'm working with is actually the RSS feed located at http://www.gjc.org/cgi-bin/rssjobs.pl

It seems to validate via the W3C RSS Feed and XML validators. When I do the following, I just get null.

$dom = new DOMDocument($xml);
$dom->loadXML($xml);
var_dump($dom->documentElement);

Am I missing something obvious? Maybe an encoding problem? Any insight would be appreciated.

3
  • 1
    What is DOMDoc the class is DOMDocument. Is it a typo or some custom library? Commented Oct 30, 2017 at 13:16
  • Because with DOMDocument it works eval.in/889459 Commented Oct 30, 2017 at 13:17
  • Aha, I finally got it to give me an actual error! "Warning: DOMDocument::loadXML(): Input is not proper UTF-8, indicate encoding ! Bytes: 0x96 0x20 0x47 0x49 in Entity, line: 257 in " Commented Oct 30, 2017 at 13:54

1 Answer 1

1

You need to convert the encoding to make it work, try the following:

$xml = file_get_contents("http://www.gjc.org/cgi-bin/rssjobs.pl");
$xml = mb_convert_encoding($xml, 'HTML-ENTITIES', "UTF-8");

$dom = new DOMDocument($xml);
$dom->loadXML($xml);
var_dump($dom->documentElement);

This will convert the characters accordingly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.