我正在使用正则表达式 from虽然这只会提取括号内的文本,但我想完全删除它:
if( preg_match( '!\(([^\)]+)\)!', $text, $match ) )
$text = $match[1];
例如我有:我的长文本字符串(带有另一个字符串)
如何获得:
$var1 = "my long text string";
$var2 = "with another string";
最佳答案
// This is all you need
<?php $data = explode('(' , rtrim($str, ')')); ?>
例子:
<?php
$str = 'your long text string (with another string)';
$data = explode('(' , rtrim($str, ')'));
print_r($data);
// output
// Array
// (
// [0] => my long text string
// [1] => with another string
// )
// profit $$$$
?>
关于PHP 将包含括号的字符串拆分为 2 个变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15359273/