FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP function(); &file=""?





digibluez
I have a a probelm with this function ...

This is take from my functions.php file
Code:
//3 OUTPUTS THE CODE WITH LINES NUMBERS( TABLE) FROM FILES
function code (){
$lines=file("/www/xampp/htdocs/network/db/code.php");
echo "<table border=0><tr><td>\n";
foreach ($lines as $line_num => $line) {
echo "$line_num<br>\n";
}
echo "</td><td>\n";
foreach ($lines as $line_num => $line) {
echo htmlspecialchars($line)."<br />\n";
}
echo "</td></tr></table>\n";
}


What i want is to change the
Code:
$lines=file("[u]/www/xampp/htdocs/network/db/code.php[/u]");

To an variable like
Code:
$codefile
and set it in a nother page to call.

like..
Code:
<?
include"functions.php";
$codefile="script1.php";
echo code();?>


I cant change it like iw ant with my curretn code it says invalid fuunction foreach.Any ideas?

[/code]
dandelion
The first thing you need is to make the $codefile variable visible from the code() function:
Code:
<?
$codefile = 'foo.php';
function code() {
    global $codefile;
   // the rest of the function code here
}
?>

Or you can pass the $codefile variable into the code() function as an argument:
Code:
<?
function code($codefile) {
    // [...]
}
code('foo.php');
?>

Please note you need not to echo the code() function because it echoes lines itself.
BlackSkad
You can't change $lines = file('blabla.txt') into one variable $code.
But you can do this instead:
Code:

function code ($code){
...
$lines = file($code);
...
}

$code = "ola.txt";
code ($code);

This works without a problem.
digibluez
Works fin like you sayd BlackSkad.thanks a lot.I'm a bit dissapointed that i didnt come ot this easy solution.I was close,but didnt get it.
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.