我想做一些非常简单的事情,但我不知道php中的正确代码。
我有一个变量$ go哪个内容是go:xxxxx
我想疑问,如果变量的内容具有" go:"的模式,其他东西会回荡,但是如果没有,请回荡另一件事
我想声明一个if语句:
if (preg_match('/GO/', $go) {
echo "something";
}
else {
echo "another thing";
,但我无法使它起作用...
我想在脚本的这一部分之间嵌入此语句:
$result = mysqli_query($enlace,"select count(distinct name2) as total from " . $table . " where go_id like '%" . $go . "%'");
$items = mysqli_fetch_assoc($result);
echo "<br/>";
echo "<b> The total number of genes according to GO code is:</b> " . $items['total'];
mysqli_free_result($result);
$result2 = mysqli_query($enlace,"select count(distinct name2) as total from " . $table . " where db_object_name like '%" . $go . "%'");
$items2 = mysqli_fetch_assoc($result2);
echo "<br/>";
echo "<b>The total number of genes according to GO association is:</b> " . $items2['total'];
mysqli_free_result($result2);
与现在一样,变量$ go可以具有诸如go的值:xxxx或一个随机句子,并且,使用此代码,我得到了两个字符串,一个字符串,一个带有值0的字符匹配$ go content。
我想要的是声明IF语句,以便它仅打印一个字符串,该字符串具有根据$ go content的匹配数,但并非两者。
有帮助吗?
使用 strpos()
:
if (strpos($go, 'GO:') !== false) {
echo 'true';
}
尝试此
echo(!strpos($ go,'go:'))?"另一件事":"某物";
一定会起作用