我需要从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">
答案 0 :(得分:1)
preg_match("/<form[^>]+>/", $content, $matches);
//the [^>]+ bit matches consecutive characters that are not ">"