On Sat, 2004-03-06 at 08:50, Labunski wrote:
> // or example I have some link:
>
> <a href='index.php?action=people'>About people</a>
>
> // so this function will output the content of people.txt file:
>
> if ($action=="people"){
> function output() {
> $file = file("data/people.txt");
> foreach($file as $value ) {
> $output .= "$value<br>";
> }
> return $output;
> }
> $content = output();
> }else{
> error ();
> }
>
> // How can I improve this function so, that it will work automaticly with
> other links (below) too.
>
> <a href='index.php?action=industry'>Factories</a>
> <a href='index.php?action=art'>Beautiful pictures</a>
> <a href='index.php?action=animals'>Zoo</a>
> <a href='index.php?action=contact'>Contact us</a>
>
> P.S.
> I have tried to improve If tag and the name of .txt file this way:
> if ($action=="$action"){
> function output() {
> $file = file("data/".$action.".txt");
>
> .. but the syntax is incorrect.
> What to do?
function output($data_file)
{
$file = file("data/$data_file.txt");
foreach($file as $value ) {
$output .= "$value<br>";
}
return $output;
}
switch($action) {
case "people":
output('people');
break;
case "industry":
output('industry');
break;
case "art"
output('art')
break;
case "animals":
output('animal');
break;
case "contact":
output('contact');
break;
}
--
Brian V Bonini <[EMAIL PROTECTED]>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php