NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
[solved] Debug PHP in HTML file


Joined: 11 Nov 2007
Posts: 12
Reply with quote
Hi,
I could'nt set breakpoints in php blocks in a html file. How could it be done?

Best regards Michael


Last edited by mife on Wed Oct 29, 2008 4:11 am; edited 1 time in total
View user's profileFind all posts by mifeSend private message
Veteran

Joined: 06 Jun 2007
Posts: 289
Location: Vancouver, Canada
Reply with quote
By default, a web server will parse only files with a .php (or .php4, .php5, etc.) extension as PHP. Files with .htm or .html extensions are seen as HTML and are not pushed through the PHP parser.

The easiest way around this is to rename your files to have .php extensions. You can still make the file content pure HTML if you wish. However, the point is that any PHP code in such files will be parsed correctly.

Another way would be to set up your web server to parse all files with .htm and .html extensions as PHP. But that is probably not a good idea as it would be "expensive" to unnecessarily parse all your HTML files that have no PHP content.

_________________
Smile
View user's profileFind all posts by annoSend private messageVisit poster's website


Joined: 11 Nov 2007
Posts: 12
Reply with quote
.


Last edited by mife on Mon Oct 27, 2008 2:17 am; edited 1 time in total
View user's profileFind all posts by mifeSend private message


Joined: 11 Nov 2007
Posts: 12
Reply with quote
Thank you for the reply anno.

There are some good reasons to let the webserver execute php in html files. To please Google and meet the expectations of users and my customers and pages have to be html. Imagine you are a web programmer like me and a customer ask you to add functionalty to an existing page. If you are asked just to add functionalty, change nothing else my answer would be not "NO, can't be done". Yours?
Another point is to hide as much as possible from malicious minds.

Wasn't php desigend exactly for that purpose, to write php in html? Is it uncommon to do so? How do cms or template systems work other than that?

So once again - is it possible for phped to reckon php code in a html file?
If not a simple no would be sufficient instead of asking me to switch my profession or change my customers Wink
View user's profileFind all posts by mifeSend private message


Joined: 14 Apr 2006
Posts: 33
Reply with quote
erm, it is possible as I've done it.

Ah, erm, actually, thinking about it, no I haven't! I do have a few HTML files that the server treats as PHP files (via the htaccess script, it changes the handler for a specific file), but they're all stubs which call php files to generate the content.

i.e. I have an index.htm file which has basically one line it in, which is include index.php.

Putting PHP code inside HTML files can be done and the server will see it as PHP code, but the debugger won't see it as a PHP file and whilst you can step through it, you won't get the normal execution point bar etc.., so you won't know which line is being run.

Its probably more of a phpEd problem than debugger problem.

The other option is to rename the html file to php when debugging and then change it back. Or do as I do, have the htm file but put the code into a PHP file and simply include it into the HTM file. Then you can set your breakpoints in the php file.

Hope you find that more useful Wink

Just thought of something else, I haven't tried it, so its just an idea - you may have already tried it anyway.

In the Settings screen in phpEd, click on the Associations item on the left and move the .htm / .html (whichever you need) association from HTML files to PHP4/5 files and see if that fools phpEd into loading it in debugger mode...

_________________
Regards

Steve.
View user's profileFind all posts by MGSteveSend private message
Re: PHP in HTML file


Joined: 17 Feb 2008
Posts: 26
Location: Alrewas, UK
Reply with quote
mife wrote:
Hi,
I could'nt set breakpoints in php blocks in a html file. How could it be done?

Best regards Michael


Isn't the answer to save your file as *.phtml? I find that the most convenient solution fo
my uses.


Regards


Will
View user's profileFind all posts by qbusterSend private messageVisit poster's websiteAIM Address


Joined: 11 Nov 2007
Posts: 12
Reply with quote
Hi,

MGSteve, your tipp done the trick!

Tools: Settings: File Associations:
Add desired extension to php and restart phped

Thanks very much to everybody who tried to help.

Regards
View user's profileFind all posts by mifeSend private message
[solved] Debug PHP in HTML file
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic