special char + eregi()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • adamluc
    New Member
    • Sep 2006
    • 1

    special char + eregi()

    Ive searched, and ive seen many tutorials but i must not be getting it. Ive tried using brackets, ive tried using escape chars but nothing is working. Perhaps im just using them in wrong order, but right now ive got everything twisted. How do i determine or find the '+' inside a string for example "2+2="?

    else if(eregi( '+' , $q ))
    {
    $a = sscanf($q, "%d+%d=", $num1, $num2);
    $answer = ($num1 + $num2);
    $response = $answer;
    }

    thanks for any help given
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    You can use the split() function, as follows:
    [PHP]
    $exp="2 + 2";
    list($num1, $num2) = split('[+]', $exp);
    $answer = $num1+$num2;
    echo "answer = $answer<br />";[/PHP]

    Ronald :cool:

    Comment

    Working...