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