954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Newbie to PHP question

Okay I am new to PHP, well getting it to run. The programming part is fine, it is very similar to python, ruby, etc... so no trouble there. So here is my problem. I made a class, and all it has is a function that writes test to the browser page.
[PHP]
<?php
class Test{

function Test(){}

public function test(){
echo "Test \n";
}
}
?>
[/PHP]

and I made a html doc that would just use that script that I did, but I dont think I did it right, so how would I use that in an html doc?
Thanks

Dark_Omen
Posting Pro
573 posts since Apr 2004
Reputation Points: 23
Solved Threads: 6
 

You don't, really. You serve a PHP file, not an HTML file. The PHP file you serve would have to call your function at some point, but you know that.

PHP, like with other web languages, runs through a "filter" before the user gets it. The filter renders the HTML by "running" the PHP.

tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 

Okay, thanks for the help.
PHP files only work with other PHP files, and I just need to make a php file with html code in it.

Dark_Omen
Posting Pro
573 posts since Apr 2004
Reputation Points: 23
Solved Threads: 6
 

Correct. You can more or less have a complete HTML file, and include PHP here and there between the PHP delimiters. However, for any of the PHP to function, you save the file with a ".php" extension.

I do that for a page on my site, where it's completely xhtml except for an RDF feed. The only php on the page is the call to the RDF parser, which outputs HTML.

However, for that one function call to work, the file is served as a PHP, not HTML.

tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You