PDA

View Full Version : Writin $vars to a txt file


stuuu
09-16-2002, 10:32 PM
<?
$write_file = strtolower("../../links/$placement.txt");
$write_me = "\n<tr>\n\t<td bgcolor=\"$s_rot_one\" width=\"30%\" align=\"left\"><font face=\"tahoma, verdana, arial, helvetica\" size=\"2\"><a href=\"$url\" target=\"_blank\">$name</a></font></td>\n\t<td bgcolor=\"$s_rot_one\" width=\"70%\" align=\"left\"><font face=\"tahoma, verdana, arial, helvetica\" size=\"2\">$description</font></td>\n</tr>";
$old_txt = file($write_file);
$fp = fopen($write_file, "w");
fputs($fp, $write_me);
for($x=0;$x<count($old_txt);$x++) {
fputs($fp, trim($old_txt[$x])."\r\n");
}
fclose($fp);
?>

As you can see from the code above, I would like PHP NOT to evaluate SOME of the $vars ($s_rot_one) in my input line ($write_me).

This is what I want to see in my text file once the above code has been executed.

<tr>
<td bgcolor="$s_rot_one" width="30%" align="left"><font face="tahoma, verdana, arial, helvetica" size="2"><a href="url" target="_blank">name</a></font></td>
<td bgcolor="$s_rot_one" width="70%" align="left"><font face="tahoma, verdana, arial, helvetica" size="2">description</font></td>
</tr>

(plus the tabs!)

Any ideas PLEASE :)

futureal
09-17-2002, 03:09 AM
You want to escape the "$" character so that PHP will not treat it as a variable name.

So this:

<td bgcolor=\"$s_rot_one\"

Should become this:

<td bgcolor=\"\$s_rot_one\"

It's basically the same as escaping the quotation marks. Hope this helps!