我已经研究了这个上下我无法弄清楚我做错了什么。我有$ _GET获得的以下变量。正则表达式不在PHP中的括号之间打印字符串
$monitorname = $_GET['monitorname'];
看起来应该类似于:985_Sands-Road(54dd14d80bd5f777184cb9c8)
,在它实际上看起来像网址:
index.php?monitorname=985_Sands-Road%26%2340%3B54dd14d80bd5f777184cb9c8%26%2341%3B&alertType=0"
我试图用正则表达式来获得括号之间的文本,这里是我的正则表达式代码:
preg_match('/\(([^)]+)\)/', $monitorname, $match);
$id = $match[1];
echo $id;
但无论我做什么,它都不会回显ID。我能看到什么并在此修复?必须指出的是,当我明确地保存字符串作为一个变量,它工作正常:
$text = '985_Sands-Road(54dd14d80bd5f777184cb9c8)';
preg_match('/\(([^)]+)\)/', $text, $match);
$id = $match[1];
echo $id;
感谢这么多提前
你有没有尝试使用'的preg_match('/%26%2340%3B(。*? )%26%2341%3B /',$ text,$ match);'?我认为这些就像是'<'和'>'。 –
@stribizhev感谢您的评论。我只是试了一下,仍然没有。 – Moe