Forum Moderators: coopster

Message Too Old, No Replies

Writing PHP to file w/fwrite()?

         

angst

9:06 pm on Sep 14, 2005 (gmt 0)

10+ Year Member



Hi,

I'm trying to write this code to a index.php file when i generate directories on my site,

like:

PHP Code:
fwrite($handle, "
<?
$file = file('http://www.somesite.com/?page=sublist&cat=$row[cid]');
foreach($file as $line){
echo $line;
}
?>
");
fclose($handle);


which seems to kind of work, but it takes some of the code out and leaves me with this inside the index.php file:

<?
= file('http://www.sometime.com/?page=sublist&cat=1');
foreach( as ){
echo ;
}
?>

seems to remove anything with a $ in front of it,
any ideas on how to get around this?

thanks in advance for your time!
-Ken

MattyMoose

11:00 pm on Sep 14, 2005 (gmt 0)

10+ Year Member



My guess is that with the double quotes, it's evaluating the variables, which you don't want...


fwrite($handle, '
<?
$file = file(\'http://www.somesite.com/?page=sublist&cat=$row[cid]\');
foreach($file as $line){
echo $line;
}
?>
');
fclose($handle);

It seems as though you may actually want $row evaluated. In that case:


fwrite($handle, '
<?
$file = file(\'http://www.somesite.com/?page=sublist&cat=' . $row[cid] . '\');
foreach($file as $line){
echo $line;
}
?>
');
fclose($handle);

Should do it.

I think I got that right. PHP masters here know better than me. :)