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 に答える