Jump to content

Variables inside a file...


devWhiz

Recommended Posts

So say I have a file with the contents..

 

; this is a comment
var2 : variable 
; another comment 
var3 : file.txt 

 

how would I be able to do

 


<?php

echo $var2; 

?>

 

That would echo "variable"

 

and


<?php

$file = file($var3);

?>

 

So its reading the file to get the variable from the text file and if the line starts with ";" its disregarded..

 

 

Thanks

Link to comment
Share on other sites

This looks straight forward CLUEL3SS. OPEN the file READ each line and examine the line for the properties your looking for. php string functions to use are found here: http://php.net/manual/en/ref.strings.php.

 

The only problem I see is "$file = file($var3);".  Why store the text file name as a variable? FILE 3 : file.txt  Maybe a better way of storing it.

 

Hope this helps, if not just speak up.

Link to comment
Share on other sites

Well, I would just use the array:

 

echo $array['var2'];

Or you could extract() the array and it would create the vars for you.

 

that worked thanks man!!

 

This looks straight forward CLUEL3SS. OPEN the file READ each line and examine the line for the properties your looking for. php string functions to use are found here: http://php.net/manual/en/ref.strings.php.

 

The only problem I see is "$file = file($var3);".  Why store the text file name as a variable? FILE 3 : file.txt  Maybe a better way of storing it.

 

Hope this helps, if not just speak up.

 

I appreciate your help as well !

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.