Jump to content
xisto Community
Jonnyabc

Php Headline Error...Error

Recommended Posts

Code included() in first of four lines of top.php:

<?xml version="1.0" encoding="UTF-8"?>



Error displayed on page:

Parse error: syntax error, unexpected T_STRING in /home/jlectro/public_html/top.php on line 1

Me scratching me head:It works on my local host using WampServer...what's up with you? Is it your encoding, or are you just not XML enough to give me a straight answer? Hm...I think I'll ask on Xisto, since they can tell me better any day of the week compared to a cryptic message.

I do understand that PHP has different versions...is this the issue? I'm trying to keep this site using XHTML standards, which includes that first line. Thanks!

Share this post


Link to post
Share on other sites

hmmm. first of all, that is standard encoding so you don't need to include it. <?xml version="1.0"?> should be correct. another option though is putting <?php echo '<?xml version="1.0"'; ?> on your first line. you also might trying to get rid of the version declaration alltogether and start your code from the second line down. try those two things... hopefully one or both will work....this is more like a programming issue than anything related to Xisto - Web Hosting. maybe a mod can move it....

Edited by anwiii (see edit history)

Share this post


Link to post
Share on other sites

<? is the shorthand for PHP; adding "xml" after it doesn't help PHP tell the difference. Use anwiii's suggestion by using echo or print instead of just simply including the XML. You can use file_get_contents() if you want.

 

Your WAMP server is probably configured to avoid using the PHP shorthand.

Share this post


Link to post
Share on other sites

If you are not actually using XML in your application, that line can be deleted and the confusion goes away.Otherwise, echo the html equivalent of the "<?" and the error may go away.

Share this post


Link to post
Share on other sites

Please copy-paste the first 10 lines of your code and show us. It will be much easier to debug your app. rather than jumping to conclusions.

Share this post


Link to post
Share on other sites

yea, i agree. after i wanted to see the rest of the code, it was too late to edit so i shouted it. we really do need to see the code because even my ideas are assumptions. also, just because it says line 1 doesn't mean it's on line one. i really hate those errors. i used to get a lot of them in the past.

Please copy-paste the first 10 lines of your code and show us. It will be much easier to debug your app. rather than jumping to conclusions.

Share this post


Link to post
Share on other sites

Hi!You don't really have a problem with your code, but it's just the XML tag at the top that is causing the issue. As a previous poster suggested, you can echo/print the tag using a PHP statement or get one of the support folk to help you disable short tags in PHP. In fact, this is one of the reasons why the PHP community insists on avoiding short tags - I actually liked the <?= $variable-name ?> syntax though I stop using it for concerns over whether the host would support it. I would imagine WAMP has short tags disabled by default, but if you do enable it, you can get the same error that you see on the Xisto - Web Hosting servers.BTW, if you are working on anything that you intend to release as open-source, somebody from the forum could probably help out too and take care of all of your coding woes.

Share this post


Link to post
Share on other sites

Sorry guys...here it is! Of course I can't check anything until the server or my site gets fixed because EVERYTHING is down at the moment (I can't even connect to the cPanel or via FTP).

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd; <html xmlns="http://www.w3.org/1999/xhtml/ ; xml:lang="en" lang="en"> <head> <title>J L-ectronics.com - Home</title> <link rel="stylesheet" type="text/css" href="../resources/css/main.css" /> <link rel="alternate" type="application/rss+xml" title="J L-ectronics" href="../resources/rss/main.rss" /> <link rel="icon" type="favicon" href="../resources/img/favicon.ico" /> <link rev="made" href="mailto:contact@jl-ectronics.com" /> <meta name="keywords" content="J L-ectronics, J L, JL, J, ectronics, lectrinics, electronics, news, hardware, operating system, software, utility, application, internet, research and development r and d, rd, r&d" /> <meta name="description" content="We cover a wide variety of topics and resources on electronics. If you have ever been interested in anything computer related, regardless of your skill, the category or anything else, then you will be glad to explore the many opportunities that await you. When you are done, you may find new hobbies or potential careers that you never thought about before. Enjoy J L-ectronics.com!" /> <meta name="author" content="Jonathan L" /> <meta name="robots" content="all" /> <meta name="geo.position" content="39.7684; -86.1580" /> <meta name="geo.country" content="US" /> <meta name="geo.region" content="US-IN" /> <meta name="geo.placename" content="Indianapolis, Indiana" />
 

Notice from truefusion:

All code must reside in either CODE, CODEBOX or HTML. Review the BB codes on how to use BB codes.

Share this post


Link to post
Share on other sites

Usually, under local condition, your error reporting is turned off. Therefore, you do not see the error message through your hosting account.PHP's execution cue is "<?" Therefore, normal XML encoding declaration will not work as PHP file.Instead, you can use PRINT function to display the encoding, so that

<?php print"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd;<html xmlns="http://www.w3.org/1999/xhtml/ ; xml:lang="en" lang="en"><head><title>J L-ectronics.com - Home</title><link rel="stylesheet" type="text/css" href="../resources/css/main.css" /><link rel="alternate" type="application/rss+xml" title="J L-ectronics" href="../resources/rss/main.rss" /><link rel="icon" type="favicon" href="../resources/img/favicon.ico" /><link rev="made" href="mailto:contact@jl-ectronics.com" /><meta name="keywords" content="J L-ectronics, J L, JL, J, ectronics, lectrinics, electronics, news, hardware, operating system, software, utility, application, internet, research and development r and d, rd, r&d" /><meta name="description" content="We cover a wide variety of topics and resources on electronics. If you have ever been interested in anything computer related, regardless of your skill, the category or anything else, then you will be glad to explore the many opportunities that await you. When you are done, you may find new hobbies or potential careers that you never thought about before. Enjoy J L-ectronics.com!" /><meta name="author" content="Jonathan L" /><meta name="robots" content="all" /><meta name="geo.position" content="39.7684; -86.1580" /><meta name="geo.country" content="US" /><meta name="geo.region" content="US-IN" /><meta name="geo.placename" content="Indianapolis, Indiana" />
This will pass without any issue. You can save this file as .php and it will execute without an issue.

Share this post


Link to post
Share on other sites

Usually, under local condition, your error reporting is turned off. Therefore, you do not see the error message through your hosting account.
PHP's execution cue is "<?" Therefore, normal XML encoding declaration will not work as PHP file.

Instead, you can use PRINT function to display the encoding, so that

<?php print"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; ?>



This will pass without any issue. You can save this file as .php and it will execute without an issue.


Probably is something obvious, but what's the difference between echo and print? Thanks!

Share this post


Link to post
Share on other sites

Probably is something obvious, but what's the difference between echo and print? Thanks!

Apparently not. I thought Print was this and Echo was that... My understanding was that Print will output without parsing php codes, making <?xml ... easier than let's say echo "<?xml... which PHP will try to parse.

According to other discussion boards and benchmarks, echo is faster output than print. They both parse php codes, i.e.

Print "Hello $name";

Will show the value of $name rather than the actual $name word. I always thought the output of this similar would show

Hello $name

but I am wrong, as I read other discussions.

The major difference between Print and Echo is that Print can return a value. Whatever that means, if you would have to ask that question, according to a forum, you'll never need to use it. So Print can be viewed as a function where it can return a true/false value but it's not classified as a function--it's a command.

Other than that, nothing special. So use echo instead of print.

Share this post


Link to post
Share on other sites

Probably is something obvious, but what's the difference between echo and print?

To add to what BuffaloHelp said, the fact that print returns a value can be quite interesting when using it in certain areas where you otherwise would not have thought of. For example, you can then do things like:
return print "Some debugging text or whatever.";if (print "Entering if 'here'" && $var){// ...}
print will most likely always return true.

Share this post


Link to post
Share on other sites

Just to put in my 2cents, wouldn't this also work?

<?phpinclude_once './version.xml';?>
Couldn't you point it to the xml file by doing that? I am still new to php so don't yell at me if I'm wrong :angel:

Share this post


Link to post
Share on other sites

Just to put in my 2cents, wouldn't this also work?

<?phpinclude_once './version.xml';?>
Couldn't you point it to the xml file by doing that? I am still new to php so don't yell at me if I'm wrong :angel:
I believe that was basically the same or similar code logic that the topic starter was using. The only way that would work is if that XML file you are including has this or something similar as its first line:
<?php echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; ?>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.