问题描述
如何在php中修剪一些单词?像这样的例子
How to trim some word in php? Example like
pid="5" OR pid="3" OR
我想删除最后一个OR
推荐答案
我建议使用 implode()
将这样的 SQL 表达式粘在一起.首先构建一个简单表达式的数组,然后用 OR 对它们进行内爆:
I suggest using implode()
to stick together SQL expressions like that. First build an array of simple expressions, then implode them with OR:
$pids = array('pid = "5"', 'pid = "3"');
$sql_where = implode(' OR ', $pids);
现在 $sql_where
是字符串 'pid = "5" OR pid = "3"'
.您不必担心剩余的 OR,即使 $pids
中只有一个元素.
Now $sql_where
is the string 'pid = "5" OR pid = "3"'
. You don't have to worry about leftover ORs, even when there is only one element in $pids
.
此外,一个完全不同的解决方案是将 " false"
附加到您的 SQL 字符串中,这样它就会以 "... OR false"
结尾,这将使它成为有效的表达.
Also, an entirely different solution is to append " false"
to your SQL string so it will end in "... OR false"
which will make it a valid expression.
@RussellDias 的回答是您问题的真正答案,这些只是一些可供考虑的替代方案.
@RussellDias' answer is the real answer to your question, these are just some alternatives to think about.
这篇关于如何使用 PHP 修剪文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!