这是我的代码..使用的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