1
我需要获取两个分隔符之间的内容。我正在写一个函数,以便我只能得到我想返回的部分。PHP在获取内容的范围内
HTML文件
<subject>
Subject line goes here
</subject>
<message>
Message text goes here
</message>
例如,函数可能是这样的:
功能
public function get($section = '', $template = '') {
if(empty($section)) {
return false;
}
if(empty($template)){
return false;
}
if(!file_exists($template)) {
return false;
}
$content = file_get_contents($template);
if($content) {
// Get chosen section
}
}
echo $this->get('message', 'myfile.html');
输出
Message text goes here
请注意,由于标签嵌套的方式,正则表达式通常是处理HTML文档的糟糕选择。查看链接的答案,了解更强大的替代方法。 – IMSoP 2015-04-03 14:56:21