Page 1 of 1
Defining a variable.. Within a variable.
Posted: Fri Feb 14, 2003 4:57 pm
by Jim
Code: Select all
$text = "
'$type' = "<a href='/netnews/news.php?action=add&site=$site'>$site</a>";
if($site != 0) {
echo '<a href='/netnews/news.php?action=add&site=$site'>$site</a>'
}";
That code is written a specific file each time a script is run. However, the variable "$type" is never defined within the file to which I've written. I always get blank spots
Any ideas?
Posted: Fri Feb 14, 2003 6:09 pm
by patrikG
Code: Select all
$text = "
'$type' = "<a href='/netnews/news.php?action=add&site=$site'>$site</a>";
Esacpe the second quotation-mark like this \"
So your code would read:
Code: Select all
$text = "
'$type' = "<a href='/netnews/news.php?action=add&site=$site'>$site</a>"";
On the other hand: PHP only compiles once. Meaning: if you write these file-contents to a file stored on your server which then is requested by a browser, it'll work. However, if you create this file on the fly - it won't. Reason: PHP only compiles once.
Posted: Fri Feb 14, 2003 8:47 pm
by evilcoder
where are you outputting the data you have stored in the type variable?
Posted: Fri Feb 14, 2003 9:27 pm
by Jim
All of this is going in to a file named "commands.txt". Here's the entire snippet:
Code: Select all
$fp = fopen("/home/empirega/public_html/netnews/commands.txt","w");
$text = "
'$type' = '<a href='/netnews/news.php?action=add&site=$site'>$site</a>';
if($site != 0) {
echo '<a href='/netnews/news.php?action=add&site=$site'>$site</a>'
}";
fputs($fp, $text, strlen($text));
fflush($fp);
fclose($fp);
Any further thoughts?
Posted: Fri Feb 14, 2003 9:36 pm
by Jim
Never mind. I fixed it. I defined the variable OUTSIDE that writing script and used it within the code. Worked
