On 10/18/07, Jochem Maas <[EMAIL PROTECTED]> wrote:
>
> Colin Guthrie wrote:
> > LKSunny wrote:
> >> <?
> >> $a="1+1"; //variables(string)
> >>
> >> //how can arithmetic variables(string) ??
> >> //N ROW................
> >>
> >> //output
> >> echo $a //i need output "2" not "1+1"
> >> //Please Help, Thank You Very Much !!
> >> ?>
> >>
> >
> > You can do:
> >
> > eval("echo $a;");
>
> you realise Sunny stopped reading at this point.
> some people should not be given guns. ;-)


a much safer technique is to restrict the options on the input and define a
custom function that
has expectations based upon those restrictions:

function addStringPieces($stringWAddition) {
    $addComponents = explode('+', $stringWAddition);
    return $addComponents[0] + $addComponents[1];
}
php > echo addStringPieces('1+1');
2

-nathan

Reply via email to