Hi, Saturday, March 6, 2004, 11:50:04 PM, you wrote: L> // or example I have some link:
L> <a href='index.php?action=people'>About people</a> L> // so this function will output the content of people.txt file: L> if ($action=="people"){ L> function output() { L> $file = file("data/people.txt"); L> foreach($file as $value ) { L> $output .= "$value<br>"; L> } L> return $output; L> } L> $content = output(); L> }else{ L> error (); L> } L> // How can I improve this function so, that it will work automaticly with L> other links (below) too. L> <a href='index.php?action=industry'>Factories</a> L> <a href='index.php?action=art'>Beautiful pictures</a> L> <a href='index.php?action=animals'>Zoo</a> L> <a href='index.php?action=contact'>Contact us</a> L> P.S. L> I have tried to improve If tag and the name of .txt file this way: L> if ($action=="$action"){ L> function output() { L> $file = file("data/".$action.".txt"); L> .. but the syntax is incorrect. L> What to do? L> Thanks, L> Roman do something like this: function output($action){ $output = ''; //if no file we return an empty string $fname = 'data/'.$action.'.txt'; if(file_exists($fname){ $file = file($fname); foreach($file as $value ) { $output .= "$value<br>"; } } return $output; } if(isset($_REQUEST['action'])){ $out = output($_REQUEST['action']); } -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php