Jump to content

Variable Names

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
Paradine

Paradine

    Learning Programmer

  • Members
  • PipPipPip
  • 48 posts
Hello,
If I have variable names in a text file how can I use those names as variables?

I have "cont" as a string in a file. That is read in using fopen. How can I use $cont as my variable?

#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
I believe when you use fopen, the entire content of the file is stored as a string. Therefor you would need to use some method to parse the content. Either using regex or some string functions such as sscanf.

#3
Lop

Lop

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,172 posts
So you want to turn a string into a variable? Why? You could always use an array to do this:

$myArray['cont'] 

so to apply you would use

$myArray[$str]->'value';

Where $str is the variable name from the text file.

#4
Paradine

Paradine

    Learning Programmer

  • Members
  • PipPipPip
  • 48 posts
Yes, I need the variable name to be the array. I suppose I could use an array but it is just easier when going through the list again to say print $variable instead of finding the name and searching an array.