Jump to content

PHP question (variables/Strings)

Featured Replies

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);

Cap'n beat me to the punch. Double quotes interpolate, single quotes don't.

  • Author

I knewwwww it was a stupid thing I forgot.

 

Bah! :D

 

Thanks!

 

BTW... that reminds me -- is this also the difference between "echo" and "print" ? and if not, uh, what is the difference? anyone knows?

Archived

This topic is now archived and is closed to further replies.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.