Variables and Strings

Variables and Strings

am 29.12.2005 04:30:04 von Unknown Unknown

------=_Part_61505_7286812.1135827004212
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hey everyone, is there a way to return all the variables from a string into
an array, for example
$Var1=3D"Yo";
$Var2=3D"Man";
$SQL=3D"SELECT * FROM tblname WHERE 4=3D$Var1 AND WHERE 3=3D$Var2";
$AllVars=3DMySpecialFunction($SQL);
print_r($AllVars);

would ideally print an array like:
{
array
$Var1=3D"Yo"
$Var2=3D"Man"

}
i think i should use an ereg or preg replace but I don't know much about
them or how to use them, thanks in advance

------=_Part_61505_7286812.1135827004212--

Re: Variables and Strings

am 29.12.2005 06:55:29 von Curt Zirzow

On Wed, Dec 28, 2005 at 10:30:04PM -0500, PHP Superman wrote:
> Hey everyone, is there a way to return all the variables from a string into
> an array, for example
> $Var1="Yo";
> $Var2="Man";
> $SQL="SELECT * FROM tblname WHERE 4=$Var1 AND WHERE 3=$Var2";
> $AllVars=MySpecialFunction($SQL);
> print_r($AllVars);

I'm not sure what your trying to do but well,

var_dump($Var1, $Var2, $AllVars);

Curt.
--
cat .signature: No such file or directory

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Variables and Strings

am 29.12.2005 10:23:43 von Jochem Maas

PHP Superman wrote:
> Hey everyone, is there a way to return all the variables from a string into
> an array, for example
> $Var1="Yo";
> $Var2="Man";
> $SQL="SELECT * FROM tblname WHERE 4=$Var1 AND WHERE 3=$Var2";
> $AllVars=MySpecialFunction($SQL);

your function MySpecialFunction() will recieve the following string:

"SELECT * FROM tblname WHERE 4=Yo AND WHERE 3=Man"

which apart from being (probably) incorrect SQL, is just a string -
how is your special function supposed to tell which chars are part of
the previously injected variables' values - and even more impossible:
how would the function find out what those variables we're called to
begin with (it can't).

what is it you would like to achieve?

rgds,
jochem

PS - learn to walk before you fly ;-)

> print_r($AllVars);
>
> would ideally print an array like:
> {
> array
> $Var1="Yo"
> $Var2="Man"
>
> }
> i think i should use an ereg or preg replace but I don't know much about
> them or how to use them, thanks in advance
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Variables and Strings

am 29.12.2005 22:31:44 von Unknown Unknown

------=_Part_5931_4446497.1135891904735
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Thanks for the responses guys, but what i'm saying is i would like to retur=
n
all the variable names i have in a string,
$String=3D"Blah Blah Blah $VarName Blah Blah Blah";
$Vars=3Dmyspecialfunction($Varname);
echo ($Vars);

that code would produce $Varname, if there were more variables it would als=
o
return the Variable Names in an array
On 12/29/05, Jochem Maas wrote:
>
> PHP Superman wrote:
> > Hey everyone, is there a way to return all the variables from a string
> into
> > an array, for example
> > $Var1=3D"Yo";
> > $Var2=3D"Man";
> > $SQL=3D"SELECT * FROM tblname WHERE 4=3D$Var1 AND WHERE 3=3D$Var2";
> > $AllVars=3DMySpecialFunction($SQL);
>
> your function MySpecialFunction() will recieve the following string:
>
> "SELECT * FROM tblname WHERE 4=3DYo AND WHERE 3=3DMan"
>
> which apart from being (probably) incorrect SQL, is just a string -
> how is your special function supposed to tell which chars are part of
> the previously injected variables' values - and even more impossible:
> how would the function find out what those variables we're called to
> begin with (it can't).
>
> what is it you would like to achieve?
>
> rgds,
> jochem
>
> PS - learn to walk before you fly ;-)
>
> > print_r($AllVars);
> >
> > would ideally print an array like:
> > {
> > array
> > $Var1=3D"Yo"
> > $Var2=3D"Man"
> >
> > }
> > i think i should use an ereg or preg replace but I don't know much abou=
t
> > them or how to use them, thanks in advance
> >
>
>


--
Hi Everyone, I am running PHP 5 on Windosws XP SP2 with MySQL5, Bye Now!

------=_Part_5931_4446497.1135891904735--

RE: Variables and Strings

am 29.12.2005 23:03:44 von Jay Blanchard

[snip]
Thanks for the responses guys, but what i'm saying is i would like to return
all the variable names i have in a string,
$String="Blah Blah Blah $VarName Blah Blah Blah";
$Vars=myspecialfunction($Varname);
echo ($Vars);

that code would produce $Varname, if there were more variables it would also
return the Variable Names in an array
[/snip]

And you call yourself Superman?!?

Keep in mind that the variable name in a double quoted string is
interpreted, you would have to use an outside process to read each line of
the file, locate the lines where the variables are, and then process to your
liking.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Variables and Strings

am 29.12.2005 23:04:00 von Jim Moseby

>
> Thanks for the responses guys, but what i'm saying is i would
> like to return
> all the variable names i have in a string,
> $String="Blah Blah Blah $VarName Blah Blah Blah";
> $Vars=myspecialfunction($Varname);
> echo ($Vars);
>
> that code would produce $Varname, if there were more
> variables it would also
> return the Variable Names in an array

I believe what Jochem is trying to tell you is that when you assign the
string variable, the variable names are expanded to their values, so the
names are no longer available.

Consider this:

$partname='widget';
$amount=100;

$string="This $partname costs $amount dollars";

/*
$string now equals "This widget costs 100 dollars", so when you pass it to
your function, it has no way to know for sure what the variables were, or
that there even were ANY variables involved in the generation of the string.

The variable NAMES are not passed because PHP expands them to their values
and sets $string accordingly.
*/

$string='This $partname costs $amount dollars';

$string now equals "This $partname costs $amount dollars". In this case, I
used single quotes. The values are not expanded and the variable NAMES are
passed. The VALUE of the variables are not. So you could then have a
function look for any word that starts with a $ and return an array of
names.

That all being said, what in the world are you trying to do with this? I
bet you $1.78 (the change in my desk drawer) there is a much better way to
solve whatever problem it is than the way you are trying here.

JM

Because it ruins the flow of the conversation.
>Why is top posting a bad thing?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Variables and Strings

am 30.12.2005 15:27:06 von Jochem Maas

Jim Moseby wrote:
>>Thanks for the responses guys, but what i'm saying is i would

....

>
> I believe what Jochem is trying to tell you is that when you assign the
> string variable, the variable names are expanded to their values, so the
> names are no longer available.

exactly - nicely put Jim.

>
> Consider this:
>
> $partname='widget';
> $amount=100;
>
> $string="This $partname costs $amount dollars";
>
> /*
> $string now equals "This widget costs 100 dollars", so when you pass it to
> your function, it has no way to know for sure what the variables were, or
> that there even were ANY variables involved in the generation of the string.
>
> The variable NAMES are not passed because PHP expands them to their values
> and sets $string accordingly.
> */
>
> $string='This $partname costs $amount dollars';
>
> $string now equals "This $partname costs $amount dollars". In this case, I
> used single quotes. The values are not expanded and the variable NAMES are
> passed. The VALUE of the variables are not. So you could then have a
> function look for any word that starts with a $ and return an array of
> names.

hopefully thats clear to the OP now - and he can [re]state his goal in
order that we might point him into a more fruitful direction!

>
> That all being said, what in the world are you trying to do with this? I
> bet you $1.78 (the change in my desk drawer) there is a much better way to
> solve whatever problem it is than the way you are trying here.

yeah 'Superman' explain what it is you want to do AND why - then maybe we can
give you some help - what you are currently asking is impossible (well actually
Jay Blanchard hinted at a way to do it but I firmly believe that its conceptually
over your head atm and very probably not a good solution to what you want to acheive -
which is not to say that Jays hint was crap or wrong; more like the problem you
posed originally is moot.)

>
> JM
>
> Because it ruins the flow of the conversation.

evil genius ;-)

>
>>Why is top posting a bad thing?
>
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Variables and Strings

am 30.12.2005 15:46:02 von Jay Blanchard

[snip]
yeah 'Superman' explain what it is you want to do AND why - then maybe we
can
give you some help - what you are currently asking is impossible (well
actually
Jay Blanchard hinted at a way to do it but I firmly believe that its
conceptually
over your head atm and very probably not a good solution to what you want to
acheive -
which is not to say that Jays hint was crap or wrong; more like the problem
you
posed originally is moot.)
[/snip]

We actually wrote a little code doohickey called Variable Hunter in which
the doohickey could be run within a project folder and locate all of the
variables with their respective name spaces and lines numbers. Nifty little
tool.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Variables and Strings

am 30.12.2005 15:55:52 von Jochem Maas

Jay Blanchard wrote:
> [snip]
> yeah 'Superman' explain what it is you want to do AND why - then maybe we
> can
> give you some help - what you are currently asking is impossible (well
> actually
> Jay Blanchard hinted at a way to do it but I firmly believe that its
> conceptually
> over your head atm and very probably not a good solution to what you want to
> acheive -
> which is not to say that Jays hint was crap or wrong; more like the problem
> you
> posed originally is moot.)
> [/snip]
>
> We actually wrote a little code doohickey called Variable Hunter in which
> the doohickey could be run within a project folder and locate all of the
> variables with their respective name spaces and lines numbers. Nifty little
> tool.

ah heck is that the same code that _we_ (Jay and me, etc) played with to find SQL queries?
or something that was based on it?
I remember Robin Vickery coming up with a token based variant which was rather nifty -
must look into that agian sometime!

rgds,
JOchem

>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Variables and Strings

am 30.12.2005 16:06:13 von Jay Blanchard

[snip]
ah heck is that the same code that _we_ (Jay and me, etc) played with to
find SQL queries?
or something that was based on it?
I remember Robin Vickery coming up with a token based variant which was
rather nifty -
must look into that agian sometime!
[/snip]

They are all variants of that. All nifty little tools. We should gather
those up someplace...shouldn't we?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Variables and Strings

am 30.12.2005 16:07:03 von John Nichel

Jay Blanchard wrote:
> [snip]
> yeah 'Superman' explain what it is you want to do AND why - then maybe we
> can
> give you some help - what you are currently asking is impossible (well
> actually
> Jay Blanchard hinted at a way to do it but I firmly believe that its
> conceptually
> over your head atm and very probably not a good solution to what you want to
> acheive -
> which is not to say that Jays hint was crap or wrong; more like the problem
> you
> posed originally is moot.)
> [/snip]
>
> We actually wrote a little code doohickey called Variable Hunter in which
> the doohickey could be run within a project folder and locate all of the
> variables with their respective name spaces and lines numbers. Nifty little
> tool.
>

I wrote a doohickey once which searched for all variable searching
doohickies.

--
John C. Nichel IV
Programmer/System Admin (ÜberGeek)
Dot Com Holdings of Buffalo
716.856.9675
jnichel@dotcomholdingsofbuffalo.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Variables and Strings

am 30.12.2005 16:14:16 von Jay Blanchard

[snip]
I wrote a doohickey once which searched for all variable searching
doohickies.
[/snip]

I cannot tell you how happy I am to see you use the past perfect tense
correctly there.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Variables and Strings

am 30.12.2005 16:20:49 von John Nichel

Jay Blanchard wrote:
> [snip]
> ah heck is that the same code that _we_ (Jay and me, etc) played with to
> find SQL queries?
> or something that was based on it?
> I remember Robin Vickery coming up with a token based variant which was
> rather nifty -
> must look into that agian sometime!
> [/snip]
>
> They are all variants of that. All nifty little tools. We should gather
> those up someplace...shouldn't we?
>

Well, I just purchased some domains for that. Who wants to develop it? ;)

phpdepository.com
phpdepository.org
phpdepository.net

--
John C. Nichel IV
Programmer/System Admin (ÜberGeek)
Dot Com Holdings of Buffalo
716.856.9675
jnichel@dotcomholdingsofbuffalo.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Variables and Strings

am 30.12.2005 16:23:42 von Jay Blanchard

[snip]
> They are all variants of that. All nifty little tools. We should gather
> those up someplace...shouldn't we?
>

Well, I just purchased some domains for that. Who wants to develop it? ;)

phpdepository.com
phpdepository.org
phpdepository.net
[/snip]

I'll contribute.......

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Variables and Strings

am 30.12.2005 20:39:47 von Richard Lynch

On Thu, December 29, 2005 3:31 pm, PHP Superman wrote:
> Thanks for the responses guys, but what i'm saying is i would like to
> return
> all the variable names i have in a string,
> $String="Blah Blah Blah $VarName Blah Blah Blah";

$VarName = 'xyz';
$String now has "Blah Blah Blah xyz Blah Blah Blah" in it.

There is *NOTHING* left to indicate that xyz came from a variable.

You simply do not have the context available to do what you want.

Now, you *COULD* do like this:

$VarName = 'xyz';
$Template = 'Blah Blah Blah $VarName Blah Blah Blah';

Note the use of single quotes that does NOT interpret variables.

You now have a $Template from which, with luck, you could:
A) compose $String using:
eval('$String = "$Template";');

B) use something not unlike this:
preg_match_all('/\\$([a-z0-9_]+/sU', $Template, $variables);
foreach($variables[1] as $varname){
echo "$varname = ", $$varname;
}

I'll warn you right now that whatever it is you are doing, there is
PROBABLY a better easier way to do it, but you've put on blinders to
other solutions and only asked us how to do what you think you want to
do, which is probably not what you really want to do...

--
Like Music?
http://l-i-e.com/artists.htm

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php