PHP完全自学手册(珍藏版) 中文pdf扫描版下载
<?php
function highlightWords($string, $words)
{
foreach ( $words as $word )
{
$string = str_ireplace($word, '<span class="highlight_word">'.$word.'</span>', $string);
}
return $string;
}
/*举个例子*/
$string = 'This text will highlight PHP and SQL and sql but not PHPRO or MySQL or sqlite';
/*** 从数组中读取$string里的php,sql ***/
$words = array('php', 'sql');
/*** highlight the words ***/
$string = highlightWords($string, $words);
?>
<html>
<head>
<title>PHPRO Highlight Search Words</title>
<style type="text/css">
.highlight_word{
background-color: pink;
}
</style>
</head>
<body>
<?php echo $string; ?>
</body>
</html>
function highlightWords($string, $words)
{
foreach ( $words as $word )
{
$string = str_ireplace($word, '<span class="highlight_word">'.$word.'</span>', $string);
}
return $string;
}
/*举个例子*/
$string = 'This text will highlight PHP and SQL and sql but not PHPRO or MySQL or sqlite';
/*** 从数组中读取$string里的php,sql ***/
$words = array('php', 'sql');
/*** highlight the words ***/
$string = highlightWords($string, $words);
?>
<html>
<head>
<title>PHPRO Highlight Search Words</title>
<style type="text/css">
.highlight_word{
background-color: pink;
}
</style>
</head>
<body>
<?php echo $string; ?>
</body>
</html>
转载请注明:谷谷点程序 » php让搜索的关键字变色