在MySQL表列"class“中,条目中有:
用print '<td>' .$row["klass"].'</td>';
打印全文。我能以某种方式打印直到"(“)吗?
展示:
发布于 2015-04-25 21:57:49
您可以使用preg_replace删除整个偏执:
function removeParanthesis($text) {
return preg_replace('/\s*\([^)]*\)/', '', $text);
}
print '<td>'.removeParanthesis($row["klass"]).'</td>';
会给出所需的输出。
发布于 2015-04-25 21:54:29
您可以将mysql作为
mysql> select substring_index('DS1 (1 koera toukerattavedu al.14 a.)','(',1) as klass ;
+-------+
| klass |
+-------+
| DS1 |
+-------+
所以当你选择的时候
select
substring_index(klass,'(',1) as klass
from table_name
发布于 2015-04-25 22:18:10
你可以用爆炸()功能来做
print '<td>' . explode("(", $row["klass"])[0] . '</td>';
https://stackoverflow.com/questions/29871106
复制相似问题