高级PHP正则表达式 - 解析Wordpress后期内容

时间:2013-05-09 00:07:16

标签: php wordpress

我需要从wordpress post中提取一些文本。这是一个不起作用的代码,我想可能是因为正则表达式在Expresso上工作正常,但它不适用于PHP。

$content = get_the_content();
preg_match('\<form id="form1.*?(?=<zmfj>)\', $content, $matches);
$setupform = $matches[0];
echo $setupform;

在这种情况下,变量内容可以是:

<form id="form1" method="post" action="http://google.com"><zmfj>

因此提取结果应为

<form id="form1" method="post" action="http://google.com">

1 个答案:

答案 0 :(得分:1)

preg_match("/<form[^>]+>/", $content, $matches);
//the [^>]+ bit matches consecutive characters that are not ">"