我正在尝试检测字符串是否为 *
、/
、+
或 -
,如果就是将该字符串更改为 "+"
、"-"
等(基本上是在原始字符串的每一端添加双引号)。我需要这样做,因为我需要准备这些字符串以输入到 python 脚本中,否则语法将是错误的。
这是我到目前为止尝试过的:
$input = "+";
if ($input=="*" || $input="/" || $input=="+" || $input=="-") {
$input = '"' . $input . '"';
}
echo $input;
输出总是这样:
"1"
我将如何完成我想做的事情?这将是一个输出,在这种情况下:
"+"
最佳答案
catcon 在评论中回答的问题,只需将 $input="/"
更改为 $input=="/"
关于php - 如何用引号将 '+' 或 '-' 的字符串括起来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58963318/