我想做一些非常简单的事情,但是我不知道在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内容匹配的总性能。
我想要的是声明一个if语句,以便它只打印一个字符串,这个字符串根据$go内容有匹配的数量,而不是两者都打印。
有什么帮助吗?
发布于 2016-12-15 11:08:20
使用strpos()
if (strpos($go, 'GO:') !== false) {
echo 'true';
}发布于 2016-12-15 11:38:55
尝尝这个
echo (!strpos($go,‘GO:“))?“另一件事”:“某事”;
一定会成功的
https://stackoverflow.com/questions/41162597
复制相似问题