Please use [noparse]
[/noparse] BBCode tags and indent your code to make it more readable.
I'm not exactly sure what you're asking, but, if I understand your question correctly, you want the result of your function to be printed in the [font=monospace].dispArea[/font] div?
Turn your HTML into a template.
index.php
<?php
require 'config.php';
/*
move all output to the *end* of your script (i.e., a "View", or "template" file).
It is **not possible** to print
"<div class=dispArea></div>"
to the browser and then, afterwards, add some content inside it.
PHP works *first*, ON THE SERVER. As soon as you print (echo, ?>, etc.) something, it's *gone*.
HTML works *after*, ON THE USER'S BROWSER. It has *no clue* that PHP ever existed.
*/
config.php
<?php
// you should always use brackets to define blocks.
// it will really help prevent/fix bugs.
if( isset( $_GET['run'] ) ){
$linkchoice=$_GET['run'];
}else{
$linkchoice='';
}
/*
In your functions, don't use `echo`.
Instead, `return` the text so it can be stored in a variable and inserted into your template.
*/
function myAbout(){
return 'We are just trying it for a demo.';
}
function myContact(){
return 'Thanks for contacting us';
}
/*
In your `switch`, assign your function's return value to a variable.
Make sure you choose a unique variable name so it's not accidentally overwritten
(you could also avoid this problem by using a class (object-oriented programming)).
Here, I choose to prefix the variable with `$t_` (i.e., "template").
*/
switch( $linkchoice ){
case 'About' :
$t_dispArea = myAbout();
break;
case 'Contact' :
$t_dispArea = myContact();
break;
/* add a `default` case, in case `$linkchoice` is empty or doesn't match the above cases */
default:
$t_dispArea = "Nothing to see here.";
break;
}
/*
When *all* of your content is ready, get your template.
*/
require 'template_index.php';
template_index.php
<!doctype html>
<html>
<body>
<p>Welcome to the homepage</p>
<hr>
<a href="?run=About">About</a><br>
<a href="?run=Contact">Contact</a> <br>
<a href="?run=0">Refresh No run</a>
<div class="dispArea">
<?= $t_dispArea ?>
</div>
</body>
</html><?php
/*
If you are using <PHP 5.4 and shorttags are not enabled, you'll have to do this instead:
<?php print $t_dispArea; ?>
It does excactly the same thing.
*/
// all done
exit;