mooeypoo Posted March 21, 2009 Posted March 21, 2009 Hey guys, I have a probably-silly question, but it's annoying the crap out of me. I'm reading through a config file that has the construct of: var $lala = "value"; var $lilili = "second value"; I want to read through this file line by line and output it to a second line with different values. It's really not a problem, I'm doing it already, my only problem is that whenever I want to read whether or not there's "$lala", the script seems to treat this as the inner VARIABLE $lala instead of just a text string, and since this isn't a variable in my script it returns null. Same happens when I try to output the string, IE I try to write into the new file a *text* line var $lala = "mynewvalue"; The code, again, thinks this means its supposed to search for $lala and output its *value* instead of just printing out the string as is. what do I do? How do I convince PHP to read and write this as a simple text instead of a variable? Here's the code I'm using: $origFile = "../configuration.php"; $origFileHandle = fopen($origFile, 'r') or die("Can't Open original configuration.php File"); $fullFile = Array(); while (!feof($origFileHandle)) { $line = fgets($origFileHandle); if (strstr($line,"$host = ")) { $line = ' var $host = '.$dbhost; } if (strstr($line,"$user = ")) { $line = ' var $user = '.$Properties[2]['value']; } if (strstr($line,"$db = ")) { $line = ' var $db = '.$Properties[1]['value']; } if (strstr($line,"$password = ")) { $line = ' var $password = '.$Properties[3]['value']; } if (strstr($line,"$sitename = ")>0) { $line = ' var $sitename = '.$Properties[4]['value']; } } fclose($origFileHandle);
Klaynos Posted March 21, 2009 Posted March 21, 2009 On the $line line use the function htmlentities() http://uk.php.net/manual/en/function.htmlentities.php
Cap'n Refsmmat Posted March 21, 2009 Posted March 21, 2009 Or simply enclose it in single quotes instead of double quotes. PHP does not parse variables in single-quoted strings.
D H Posted March 21, 2009 Posted March 21, 2009 Cap'n beat me to the punch. Double quotes interpolate, single quotes don't.
mooeypoo Posted March 21, 2009 Author Posted March 21, 2009 I knewwwww it was a stupid thing I forgot. Bah! Thanks! BTW... that reminds me -- is this also the difference between "echo" and "print" ? and if not, uh, what is the difference? anyone knows?
Klaynos Posted March 21, 2009 Posted March 21, 2009 echo is a language construct, print() is a function IIRC... gimmie a sec... Merged post follows: Consecutive posts mergedHere we go... http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now