Call PHP function with HTML


This is what I want…
I have a couple of .txt files:

Now i want to make a website with tree buttons and when I click on the first the txt from 1.txt is shown on the screen. When I click on the second the text of 1.txt is still there en the text of 2.txt is shown above it. Can someone help me!!

I’m trying to do this by calling the PHP function from HTML without refreshing it.

This is what I have for now…


<a href="" call inputText("tekst1.txt")>tekst1</a>
<a href="" call inputText("tekst2.txt")>tekst2</a>

function inputText ($vileName) {
$filename = $vileName;
$text = "";
$contents = @file($filename) or die("No files in guestbook.");

foreach ($contents as $line) {
	$text .= $line;

$text = split("<break>", $text);
$text = array_reverse($text); # removing this line will put newest comments at the bottom
for ($i=0; $i<count($text)-1; $i++) {
	echo "<div style=\"border: gray 0px solid; padding: 0px; font-family: arial, sans-serif; background-color: #ffffff;\">";
	echo $text[$i];
	echo "</div>";

Thanks in advance Zeb

try putting the function above the text links

just use _GET variables, with the filename in the get var, linked to by the link. IE

<a href=“yourPHPpage.php?file=tekst1”>Tekst1</a>

then in your php just use $file = $_GET[‘file’] . “.txt”;

You can’t call a PHP function from HTML. PHP is a server-side language, so it runs on the server - not in the browser.

You should use JavaScript instead as that runs in the browser. Unfortunately you don’t have access to the text files on the server then, but you can get around that by including the text from the files in the JavaScript code.

I already tried this but this removes the text that was on the screen before because the page is reloaded. What I want is that all the txt stays on the screen so when you click button 1,2,1,2
You see the text 2,1,2,1

Try using an iFrame then. And redirect the iFrame with to the php page with the correct _GET vars.

You can if you put in a .htaccess file to parse html files thru php =)

Whoow…can you tell me how?! I’m not a real superstar with PHP can you maybe give me an example??

I think this is it:

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