LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-09-2012, 10:51 AM   #1
vltreude
LQ Newbie
 
Registered: Dec 2012
Posts: 1

Rep: Reputation: Disabled
Embedded PHP in HTML- either PHP ignored or HTML broken


Please excuse this newbie question. I'm an experienced programmer with no experience in PHP.
I'm doing a website (on a Linux-hosted page on GoDaddy) where I'm trying to display a download count. A Google search told me that the easiest way is to use this PHP code:
<p>Count=<?php include("count.txt"); ?> </p>
This displays "Count=", but nothing else, so I tried another variation:
<p>Count= <?php echo file_get_contents('count.txt'); ?> </p>
That didn't work either.
I know that PHP is working because I set up the page to invoke a small PHP script to initiate the download, and that script correctly increments the contents of "count.txt" each time the download is done.
A further Google search revealed that the browser won't evaluate PHP code embedded within HTML unless the extension is changed to PHP. Unfortunately, in my case, doing this caused the browsers (Firefox, Chrome) not to display the page at all, but to bring up a screen asking what application to use to open this mysterious PHP file. So I then created an ".htaccess" file on my site which specified that HTML files were to be interpreted as PHP. Same result, except that all HTML files were broken in a similar fashion.
I must be doing something really dumb here, but my novice level prevents my from know how to phrase the question intelligently. How do I get this embedded PHP code to to parsed without breaking the HTML?
Thanks in advance for any help you can give me.
 
Old 12-10-2012, 02:35 AM   #2
rylan76
Senior Member
 
Registered: Apr 2004
Location: Potchefstroom, South Africa
Distribution: Fedora 17 - 3.3.4-5.fc17.x86_64
Posts: 1,552

Rep: Reputation: 103Reputation: 103
What do you see if you browse to a simple file (call it whatever you like) which you create to contain this:

<?php
phpinfo();
?>

after removing the .htaccess setting?

This should bring up some kind of response. If you see the above text again, you're not parsing PHP on your webserver and it is something your service provider will need to help you with.

Also, what are the permissions on the text file you are trying to read? It needs to be readable to "other" I think, eg. its user-group-other rights triplet should be something like rwxr--r--

Your logic seems ok to me otherwise, it should work as you expect... finding out why is the key here.

Alternatively, you can also try opening the file manually and reading its contents back, then echoing to the browser, instead of using the file_get_contents function call you're using...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] PHP and HTML dingo-den Linux - Software 6 11-03-2012 03:44 AM
php in html johnh10000 Programming 2 01-25-2010 05:53 AM
html vs. php feder Programming 9 11-02-2007 08:45 AM
Apache rending php when filename is x.php.html mastahnke Linux - Server 6 01-22-2007 08:39 AM
html into php charnel Programming 7 08-30-2005 10:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration