강조 단어와 같은 각 검색 단어에 대해 HTML 태그를 래핑하는 방법. 여기에 내 코드를 시도했지만 아무 것도 변경되지 않았습니다. 문제가있는 곳이나 다른 좋은 방법이 있습니까? 감사.PHP 각 검색 단어에 대해 HTML 태그를 래핑하는 방법
<?php
$sentence = "for loops are the most complex loops in PHP. They behave like their C counterparts";//original
$search = 'php counterparts';//search words
$str = explode(' ',$search);//explode every search word
for($i=0;$i<10;$i++){
if($str[$i]!=''){ //make sure if $str[$i] is not empty, do $newstr.
$newstr .= '\'<b>'.$str[$i].'</b>\','; //wrap <b> tag for search words
}
}
$newstr = substr($newstr, 0, strlen($newstr)-1);//remove last common, combine a array
$new = str_ireplace(array($str),array($newstr),$sentence);
echo $new;
?>
당신은 더 나은 당신이 일을하려고하는 무엇인지 설명 할 수 있습니까? 매우 주석이 달린 코드는 일을 결코 설명하지 않습니다. 달성하려는 결과물은 무엇입니까? – JRSofty