# Call PHP function with HTML

**URL:** <https://forum.kirupa.com/t/call-php-function-with-html/57868>\
**Category:** Uncategorized\
**Created:** [July 16, 2004, 10:59pm UTC](https://forum.kirupa.com/t/call-php-function-with-html/57868 "2004-07-16T22:59:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![zebdaag](https://avatars.discourse-cdn.com/v4/letter/z/53a042/32.png) [@zebdaag](https://forum.kirupa.com/u/zebdaag)\
**Post date:** [July 16, 2004, 10:59pm UTC](https://forum.kirupa.com/t/call-php-function-with-html/57868/1 "2004-07-16T22:59:36Z")

</div>

Hi

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

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…

```php
<html>
<head>
<title>Update</title>
</head><body>

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

<?PHP
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>";
}
}
?>
</body>

```

Thanks in advance Zeb

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 17, 2004, 2:44am UTC](https://forum.kirupa.com/t/call-php-function-with-html/57868/2 "2004-07-17T02:44:10Z")

</div>

try putting the function above the text links

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 17, 2004, 4:00am UTC](https://forum.kirupa.com/t/call-php-function-with-html/57868/3 "2004-07-17T04:00:31Z")

</div>

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”;

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 17, 2004, 8:29am UTC](https://forum.kirupa.com/t/call-php-function-with-html/57868/4 "2004-07-17T08:29:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 17, 2004, 3:42pm UTC](https://forum.kirupa.com/t/call-php-function-with-html/57868/5 "2004-07-17T15:42:38Z")

</div>

> [@Yeldarb](#):
>
> 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”;

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 17, 2004, 3:46pm UTC](https://forum.kirupa.com/t/call-php-function-with-html/57868/6 "2004-07-17T15:46:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 18, 2004, 5:49am UTC](https://forum.kirupa.com/t/call-php-function-with-html/57868/7 "2004-07-18T05:49:49Z")

</div>

> [@Hans Kilian](#):
>
> 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.

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 18, 2004, 11:07am UTC](https://forum.kirupa.com/t/call-php-function-with-html/57868/8 "2004-07-18T11:07:08Z")

</div>

> [@Marble](#):
>
> 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??

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 18, 2004, 6:36pm UTC](https://forum.kirupa.com/t/call-php-function-with-html/57868/9 "2004-07-18T18:36:01Z")

</div>

I think this is it:

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