在字符串中查找特定位置的值

时间:2013-12-16 09:59:16

标签: php math

如何使用PHP在字符串中的特定位置找到值?

与字符串“1 + 3 = 4”相似:

  1. 将字符放在变量<+ li>中的'+','*','/'或' - '之前
  2. 将加号放入变量中。它可能是'+','*','/'或' - '
  3. 将“+”,“*”,“/”或“ - ”后面的字符放在变量中
  4. 将'='后面的字符放在变量
  5. 与字符串“7 * 9 = 63”相似:

    $first = "7";
    $mathSymbol = "*";
    $second = "9";
    $answer = "63";
    

    并且“15 + 120 = 135”:

    $first = "15";
    $mathSymbol = "+";
    $second = "120";
    $answer = "135";
    

2 个答案:

答案 0 :(得分:1)

$str = "7+9=16";
for($i = 0; $i < (strlen($str)); $i++){
   if($str[$i] != '='){
    $str.$i = $str[$i];
    //echo $str[$i];//To see what it contains
   }
}

答案 1 :(得分:0)

你可以试试这个。这可能对你有所帮助 link

相关问题