這是我的代碼..使用的preg_match和STR更換,以找到一個詞,並強調它
<?php
// first get all the html contents
$page = file_get_contents('http://www.planetled.com.au/blog/what-is-a-led-spotlight/');
//next explode it
$words = explode(" ", $page);
// then display the 21st word or any word you like
echo $words[22]; // 21st word
?>
下一個我想要的是找到21人可讀字。我正在考慮用preg_match
找到這個詞,然後使用str_replace
,但是我缺少的是我會在preg_match中使用哪個模式?謝謝。
21字的索引爲20,而不是22 – rsplak 2012-08-07 14:27:26
那麼你可以肯定在加載該頁面是從字面上只是一個單詞的列表,或者是有其他的內容那裏?如果是這樣,你的'爆炸'將受到影響。此外,數組的第21個鍵是'$ arr [20]',而不是21(因爲0是第一個)。 – Utkanos 2012-08-07 14:27:41
這可能有助於:http://stackoverflow.com/questions/9304212/sed-replacing-nth-word-with-matched-pattern – mlishn 2012-08-07 14:28:05