我有一個PHP preg_match_all
和REGEX問題。使用REGEX引號內的轉義引號
我有以下代碼:
<?php
$string= 'attribute1="some_value" attribute2="<h1 class=\"title\">Blahhhh</h1>"';
preg_match_all('/(.*?)\s*=\s*(\'|"|&#?\w+;)(.*?)\2/s', trim($string), $matches);
print_r($matches);
?>
似乎不是皮卡逃過實例的報價,我想在HTML通過與報價。我已經嘗試了很多解決方案,用引號REGEX修補程序中的基本引號,但似乎沒有任何解決方案適用於我。我似乎無法將它們正確放置在這個預先存在的REGEX中。
我不是REGEX高手,有人能指點我嗎?
我想達到的效果是這樣的:
Array
(
[0] => Array
(
[0] => attribute1="some_value"
[1] => attribute2="<h1 class=\"title\">Blahhhh</h1>"
)
[1] => Array
(
[0] => attribute1
[1] => attribute2
)
[2] => Array
(
[0] => "
[1] => "
)
[3] => Array
(
[0] => some_value
[1] => <h1 class=\"title\">Blahhhh</h1>
)
)
感謝。
我們可以知道你在這段代碼中究竟做了什麼? – anubhava 2012-04-19 19:28:10
你想要得到什麼? – 2012-04-19 19:28:59