我想如果有人可以帮助我使用正则表达式或PHP中的任何方法来获取readme.html文件中的WordPress版本,就像这样:
<h1 id="logo" style="text-align: center">
<img alt="WordPress" src="wp-admin/images/wordpress-logo.png" />
<br /> Version 2.8.1
</h1>
谢谢!
答案 0 :(得分:4)
preg_match("/Version\s+([\d.]+)/", $html, $match);
$version = $match[1];
$doc = new DOMDocument;
$doc->loadHTML($html);
$text = trim($doc->getElementsByTagName("h1")->item(0)->textContent);
$index = strrpos($text, " ");
$version = substr($text, $index+1);
答案 1 :(得分:0)
你不需要那个。而是使用get_bloginfo('version');
get_bloginfo('version')
- 返回您使用的WordPress版本。此数据是从wp-includes / version.php中设置的'$ wp_version'变量中检索的。
http://codex.wordpress.org/Function_Reference/get_bloginfo