我有一个这样的文字模板:
<p>fullname = #fullname#</p>
<p>company = #company#</p>
<p>phone = #phone#</p>
<p>phone = #phone4#</p>
<p>phone = #phone5#</p>
<p>phone = #phone6#</p>
<p>phone = #phone7#</p>
<p>phone = #phone8#</p>
在这里,我想提取所有这些由#= this =&gt;分隔的文本。全名,公司,电话,...
这个正则表达式或其他什么方法的最佳方法是什么?
答案 0 :(得分:1)
你走了。利用preg_match_all
<?php
$str= '<p>fullname = #fullname#</p>
<p>company = #company#</p>
<p>phone = #phone#</p>
<p>phone = #phone4#</p>
<p>phone = #phone5#</p>
<p>phone = #phone6#</p>
<p>phone = #phone7#</p>
<p>phone = #phone8#</p>';
preg_match_all('/#(.*?)#/', $str, $matches);
print_r($matches[1]);
<强> OUTPUT :
强>
Array
(
[0] => fullname
[1] => company
[2] => phone
[3] => phone4
[4] => phone5
[5] => phone6
[6] => phone7
[7] => phone8
)