# 一千萬個為什麽

## 有沒有辦法優化在頁面上查找文本項（不是正則表達式）

//Get the HTML and look at the text nodes
$html = str_get_html($buffer);
//First we match the <body> tag as we don't want to change the <head> items
foreach($html->find('body') as$body) {
//Then we get the text nodes, rather than any HTML
foreach($body->find('text') as$text) {
//Then we match each term
foreach ($terms as$term) {
//Match to the terms within the text nodes
$text->outertext = str_replace($term, ''.$term.'',$text->outertext);
}
}
}


## 最佳答案

foreach($html->find('body/text') as$body) {
...
}