Help with turning string into global value method

Hello, I would like help to convert the following string into a global variable, gathering the left side as the variable name, and the right side as the value.

Example String: “NAME=Jim AGE=37 LOCATION=UK”

I want to make $GLOBAL[‘dataNAME’] will equal Jim and so on.

Why would you want to make anything global? If it will never change make it a constant. If the context is known, there are better ways to accomplish the task.

If you want an argument (variable) to go from page to page and isn’t security sensitive then using $_SESSION might be the way to go.

an example:
you would put this in an utility or config file at the top of each page
[php]session_start();
$username = (isset($_SESSION[‘username’])) ? $_SESSION[‘username’] : ‘Guest’; [/php]

Then all you would have to do in the page is do something like this (Most likely at the login page):
[php]$_SESSION[‘username’] = ‘Miguel Cabrera’;[/php]

or course there are many other ways to have variables go from page to page and have better security, but this is the low-down dirty method of doing it. :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service