mellis95 Posted November 28, 2009 Share Posted November 28, 2009 I just can't get my syntax correct. Could someone help me please? I am trying to write a connect file for inclusion as part of the installation routine for an app I am working on. I need this line to be: $hostname="whatever the use typed on the previous page"; Here is the code I am attempting to use: $dir="../includes2/"; $file="connect.inc"; $handle=fopen($dir.$file,'w'); $data="<?php\n"; fwrite($handle,$data); $data="$hostName ='" . $loc . "'; "; fwrite($handle,$data); fclose($handle); echo "Check and see if it worked." ?> The line in question is : $data="$hostName ='" . $loc . "'; "; So far, I have only been successful at getting the following end result: <?php ='localhost'; What escape characters do I need to use to "$" without php looking for a variable value? Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/183171-help-with-writing-with-fopen/ Share on other sites More sharing options...
mrMarcus Posted November 28, 2009 Share Posted November 28, 2009 <?php $str = '$var'; echo $str; //prints $var ?> alternatively: <?php $str = "\$var"; //the backslash \ escapes the $ character and is used for escaping in PHP echo $str; //prints $var $str2 = "<a href=\"http://www.example.com\">website</a>"; echo $str2; //will output <a href="http://www.example.com">website</a> to the browser //while... $str2 = "<a href="http://www.example.com">website</a>"; echo $str2; //will produce a parse error since the double-quotes in the string were not escaped ?> EDIT: <?php $var = 'variable'; $str = "$var"; echo $str; //prints variable ?> anything within double-quotes " will be parsed by PHP .. anything within single-quotes ', will not (will be displayed as written) Link to comment https://forums.phpfreaks.com/topic/183171-help-with-writing-with-fopen/#findComment-966704 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.