0

我在 wordpress 中遇到了一个非常奇怪的问题。

我将帖子内容作为变量获取,然后对变量进行 preg_match 没有结果。然后,当使用作为变量的字符串而不是变量本身时,一切正常。这让我发疯,有人可以帮助我吗?

// This doesn't work, I checked a thousand times and inside the $content variable 
// is the same string as I use below
$content = the_content();
preg_match('/<iframe.*src=\\"(.*)\\".*><\\/iframe>/is', $content, $matches);
return $matches;

// This works perfect?
$content = the_content();
preg_match('/<iframe.*src=\\"(.*)\\".*><\\/iframe>/is', "this is a string containing <iframe ...", $matches);
return $matches;
4

1 回答 1

3

the_content()只是打印字符串。

你应该get_the_content()像这样使用:

$content = get_the_content();
preg_match('/<iframe.*src=\\"(.*)\\".*><\\/iframe>/is', $content, $matches);

http://codex.wordpress.org/Function_Reference/the_content http://codex.wordpress.org/Function_Reference/get_the_content

于 2013-05-22T11:29:51.460 回答