我有一个包含很多行的MySQL表列。
以下是数据格式的示例:
TEST-DATA (ID:123)
如何使用PHP正则表达式删除部件(ID:123)
?
请注意,(ID:123)
包含表格列中每行的不同数字。
TESTDATA2(ID:1)
DATAAGAIN(ID:78)
MOREDATA(ID:45)
...
答案 0 :(得分:4)
试试这个:
$string = preg_replace( '/\(ID:[0-9]+\)/', '', $string );
答案 1 :(得分:4)
您可以使用preg_replace()
。
preg_replace - 执行正则表达式搜索并替换
示例:
echo preg_replace("/\([^\)]+\)/", "", $value);
表达分解:
/ - Opening delimiter
\( - Match an opening parenthesis
[^\)]+ - Match one or more characters that are not a closing parenthesis
\) - Match a closing parenthesis
/ - Closing delimiter
将$value
替换为列值的变量。