LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   PHP Functionality (https://www.linuxquestions.org/questions/linux-server-73/php-functionality-845078/)

The Godfather 11-18-2010 09:14 AM

PHP Functionality
 
Hello,

I'm sure I'm doing something rather silly but I cannot work out what is going on. I have recently downloaded and installed Fedora 14 on my server. I am trying to write some PHP. I cannot however, get some of its functionality to work.

Here's an example: SimpleXmlElement. I read that it is part of the core PHP package and thus no 'import'/'include'/etc. is needed. However, on my server, using Firefox 3.6.12, the webpage just crashes on the line

Code:

$x = new SimpleXmlElement($content);
and I get no output afterwards.

Running it in the command prompt I get, what looks like, the correct output, but with these added warnings, which I don't understand:

Code:

PHP Warning:  SimpleXMLElement::__construct(): Entity: line 8: parser error : Entity 'raquo' not defined in includes/functions.php on line 7

PHP Warning:  SimpleXMLElement::__construct():        <title>Nettuts+ &raquo; We are making some changes!</title> in includes/functions.php on line 7

PHP Warning:  SimpleXMLElement::__construct():                                ^ in includes/functions.php on line 7

PHP Warning:  Invalid argument supplied for foreach() in includes/functions.php on line 11

I have used the code provided here:

http://net.tutsplus.com/demos/08_RSS...eeds/index.php

I know it works as I've tried it on another server successfully. My first thought was that that it maybe some configurations in httpd.conf, but I am not sure.

I'm rather confused! Any help would be greatly appreciated.

Thanks in advance,
The Godfather

fcintron 11-18-2010 09:31 AM

Quote:

Originally Posted by The Godfather (Post 4163175)
Hello,

I'm sure I'm doing something rather silly but I cannot work out what is going on. I have recently downloaded and installed Fedora 14 on my server. I am trying to write some PHP. I cannot however, get some of its functionality to work.

Here's an example: SimpleXmlElement. I read that it is part of the core PHP package and thus no 'import'/'include'/etc. is needed. However, on my server, using Firefox 3.6.12, the webpage just crashes on the line

Code:

$x = new SimpleXmlElement($content);
and I get no output afterwards.

Running it in the command prompt I get, what looks like, the correct output, but with these added warnings, which I don't understand:

Code:

PHP Warning:  SimpleXMLElement::__construct(): Entity: line 8: parser error : Entity 'raquo' not defined in includes/functions.php on line 7

PHP Warning:  SimpleXMLElement::__construct():        <title>Nettuts+ &raquo; We are making some changes!</title> in includes/functions.php on line 7

PHP Warning:  SimpleXMLElement::__construct():                                ^ in includes/functions.php on line 7

PHP Warning:  Invalid argument supplied for foreach() in includes/functions.php on line 11

I have used the code provided here:

http://net.tutsplus.com/demos/08_RSS...eeds/index.php

I know it works as I've tried it on another server successfully. My first thought was that that it maybe some configurations in httpd.conf, but I am not sure.

I'm rather confused! Any help would be greatly appreciated.

Thanks in advance,
The Godfather

I could be a problem with your php version. What version does it have the server where you tried it?

What version does it have your computer?


Made a simple test.php page with this content:

<?php phpinfo();?>

And compare the output between that server where it works and your computer.


Regards

The Godfather 11-18-2010 09:50 AM

Hi fcintron,

Quote:

Originally Posted by fcintron (Post 4163191)
What version does it have the server where you tried it?

PHP Version 5.2.6-1+lenny8

Quote:

Originally Posted by fcintron (Post 4163191)
What version does it have your computer?

5.3.3

rylan76 11-23-2010 06:11 AM

Why not try something simpler, like the suggested phpinfo() call, or even

Code:

<?php

echo "Hello World!";

?>

If you see this, your PHP instance IS working in the first place. If it is, you can start debugging further from there what might be wrong about the other code that you originally posted.

The Godfather 11-24-2010 10:01 AM

Hi Ryan,

Thanks for your help.

Quote:

Originally Posted by rylan76 (Post 4168079)
Why not try something simpler, like

Code:

<?php

echo "Hello World!";

?>


This returns "Hello World!". The PHP installation is working. I have written code, setup forums, wikis etc. but for some reason, I can't get the above code to work. It seems to work on the command line, i.e. when i execute:

Code:

php index.php
I'm so confused.

Guttorm 11-25-2010 04:35 AM

Hi

Can you post the XML file you are trying to parse? From the error message it looks like it's not proper XML. This is incorrect:

Code:

<xml>
<title>Nettuts+ &raquo; We are making some changes!</title>
</xml>

This is correct:

Code:

<xml>
<title>Nettuts+ » We are making some changes!</title>
</xml>

Try to open the XML file in some browser and see if you get any errors.

I also got XML parse errors upgrading PHP to the newer versions. It seems the older versions allowed many weird XML files, whereas the newer versions are more strict.

For example, some XML files coming from some .NET application had the prefix <?xml version="1.0" encoding="unicode"?>. It was actually UTF-16LE and older versions of PHP would parse it, but not the newer ones. After changing the prefix to <?xml version="1.0" encoding="UTF-16"?> they parsed fine.


All times are GMT -5. The time now is 06:55 PM.