-1

誰かが次のようなreadme.htmlファイルでWordPressバージョンを取得するための正規表現またはPHPの任意のメソッドを手伝ってくれるといいのですが。

<h1 id="logo" style="text-align: center">
<img alt="WordPress" src="wp-admin/images/wordpress-logo.png" />
<br /> Version 2.8.1
 </h1>

ありがとうございました!

4

2 に答える 2

4

純粋な正規表現

preg_match("/Version\s+([\d.]+)/", $html, $match);
$version = $match[1];

DOMDocumentを使用

$doc = new DOMDocument;
$doc->loadHTML($html);
$text = trim($doc->getElementsByTagName("h1")->item(0)->textContent);
$index = strrpos($text, " ");
$version = substr($text, $index+1);
于 2013-01-18T18:58:46.817 に答える
0

あなたはそれを必要としません。代わりに使用するget_bloginfo('version');

get_bloginfo('version')-使用しているWordPressのバージョンを返します。このデータは、wp-includes/version.phpで設定された「$wp_version」変数から取得されます。 http://codex.wordpress.org/Function_Reference/get_bloginfo

于 2013-01-18T19:02:07.053 に答える