Hi everyone, I'm a newbie to this board, but I'm trying my best to learn.

I'm setting up a new domain/website to use .php. I used the following instructions given to me:

Converting your HTML flies to PHP

Opened a file in "CoffeeCup" html editor, called 'index.htm'. At the very top of the page, before even the <html> tag add this code:


<?
echo "Testing that PHP is running ok... success!";
?>


Now we have a page ready to test for PHP...lets add the PHP functionality for your HTML pages.

Download this file: (Its in a .zip)

AddType application/x-httpd-php .htm .html

and upload it to the root directory of your website, then rename it to '.htaccess'
This tells your website server to look for any .htm or .html pages and treat them as if they where a .php page... all without even renaming your pages!

Now upload the 'index.htm' page that you added the PHP code to, to your website, and open up your web browser. Type in the name of the uploaded index.htm page, eg; www.mydomain.com/index.htm

If PHP is running properly, you should see the message "Testing that PHP is running ok... success!".

I did all that........

When I tried to open up the index.htm in my browser (Mozilla Firefox 3.5.7) I got the following error message:

Parse error: syntax error, unexpected T_STRING in /home5/user/public_html/mynewdomain/index.html on line 1

here is the top of 'index.htm' page:


<? 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">
<?
echo "Testing that PHP is running ok... success!";
?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>


In line one, I tried <?php xml version="1.0" encoding="UTF-8"; ?>

I still get the same parse error for line one. Can someone help me please?

Many thanks in advance...

Mike

    Not sure who gave those instructions to you, but I'd recommend finding a better guide...

    1. Using the "<? ... ?>" short-tags (as well as "<?=$var;?>") has been deprecated for some time; don't use them, and instead you should be using the full "<?php ?>" tags.

    2. As short tags can cause problems (especially with XML tags, as you've found), you should disable them in your php.ini file.

    3. Mike38 wrote:

      This tells your website server to look for any .htm or .html pages and treat them as if they where a .php page... all without even renaming your pages!

      I don't really see why it's such a good thing that your webserver will call the PHP interpreter for every .htm/.html page requested. Personally, I would get rid of this and instead just use the .php file extension.

    4. Mike38 wrote:

      In line one, I tried <?php xml version="1.0" encoding="UTF-8"; ?>

      Not sure what your intent was, here, but the proper XML/XHTML tag looks like so:

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

      Thus, if you wanted to use PHP to output that data, then just [man]echo[/man] (or [man]print[/man]) a [man]string[/man] containing just that:

      <?php echo '<?xml version="1.0" encoding="UTF-8">'; ?>

    EDIT: Also, just out of curiosity... what version of PHP are you using?

      Hi Brad, I am an Internet Marketer. I am trying to get a third party tracking program that I bought, to track all of my campaigns. Its name is: 'Affiliate Prophet'. Every site that it tracks in MUST be in .php. This is a very powerful program, but the developer has just about abandoned it, and left us with no support. So, you are left to your own devices. I want to use it. Thats the reason for the code allowing html or php to run. That way, I don't have to rename countless files every time I want to do something.

      After I posted my question on this board, I tried something else, and after the change, when I type in the domain in the browser, I get the message now, "Testing that PHP is running ok... success!" Heres what I did to line #1, the offending line.

      Here is the what line #1 looked like at first and gave me the parse syntax error:

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

      I changed it to this, and it still wouldn't work:

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

      Then I changed it to this, and got the php success message in my browser:

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

      I'd like your opinion on this though. If their is a better way to do what I'm trying to do, I would like to try it. I'm going to stay with learning PHP. That can't hurt me!
      I hope my fix was correct. It looks to be just straight html now. At the beginning of line 1
      I left out the (?) question mark, and just used <>.

      I don't know what my version of PHP is Brad, how can I find out?

      Mike

      Edit by admin: no contact info permitted on the forum, thank you

        Reread his post

        bradgrafelman;10941392 wrote:
        1. Using the "<? ... ?>" short-tags (as well as "<?=$var;?>") has been deprecated for some time; don't use them, and instead you should be using the full "<?php ?>" tags.

        2. As short tags can cause problems (especially with XML tags, as you've found), you should disable them in your php.ini file.

        3. <?php echo '<?xml version="1.0" encoding="UTF-8">'; ?>

          I would suggest you try something like this.
          Everything is XHTML, except for 1 line in <body>

          <?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>
          </head>
          <body>
          
          <?php
          echo "Testing that PHP is running ok... success!";
          ?>
          
          </body>
          </html>

            Hi guys, well...I tried what you suggested above:

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

            That won't work. I get the parse error again when you add the (?) question marks. The only way it will work, is within <> only.

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

            But, it seems to be working. I was able to rename my index.html file to index.php.
            Thanks very much for everyones input. It surely is appreciated.

            Mike

              I wonder if maybe your server does not accept XML scripts.
              In my own personal server I have a variable
              $_SERVER["HTTP_ACCEPT"] = text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
              This means html, xhtml and xml is accepted by server.

              You can test this $_SERVER variable by simply

              <?php
              
              echo $_SERVER["HTTP_ACCEPT"];
              
              ?>

              ... or run a full [man]phpinfo[/man]

              <?php
              
              phpinfo();
              
              ?>

                Mike, you need to turn off short tags if you want that XML line to be treated properly. bradgrafelman explained this, and that it was causing the problems. Turn them off!

                If you can't turn them off, then take out that xml line, or find some hosting that does allow you to turn them off. Short tags cause major problems as soon as you need to do anything XML based within PHP.

                  Ashley...success! Thanks a lot for the advice. Also to Brad and everyone else. I went into my php.ini file, lo and behold on line 77 it said, "77 short_open_tag = On". I changed it to 'Off'. I changed line 1 to read, "<?xml version"1.0" encoding="UTF-8"?>. I re-tested my index.php file in my browser and got the "Testing that php is running ok... Success" line.

                  I have learned! I want to KEEP learning about php. It seems to be a very powerful script. Some of my counter-parts on my tracker forum really struggle. Some of them are very sharp! Most when they have a problem, throw their hands up, and curse the program and developer rather than try to figure out what's wrong. I'm glad I came to this forum. I hope to learn more from all of you good folks. Thanks again for your expertise...you're pretty sharp cookies! 🙂

                  Mike

                    Many thanks to everyone that came to my assistance. The problem appears to be fixed, and I have learned something about php.

                    Mike

                      Write a Reply...