本文整理汇总了PHP中string::highlight方法的典型用法代码示例。如果您正苦于以下问题:PHP string::highlight方法的具体用法?PHP string::highlight怎么用?PHP string::highlight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类string
的用法示例。
在下文中一共展示了string::highlight方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: highlight
function highlight($query, $content)
{
$point_dl = 100;
$query = string::utf2win($query);
$content = string::utf2win($content);
$content = strip_tags($content);
$content_st = $content_and = '';
$point = stripos($content, $query);
$point1 = $point - $point_dl;
if ($point1 < 0) {
$point1 = 0;
} else {
$content_st = '...';
}
$len = strlen($content);
$point2 = $point + $point_dl;
if ($point2 < $len) {
$content_end = '...';
} else {
$content_end = '';
}
$content = $content_st . substr($content, $point1, $point2) . $content_end;
$content = str_ireplace($query, '<span style="background-color: yellow; color: black;">' . $query . '</span>', $content);
$query = string::win2utf($query);
$content = string::highlight(string::win2utf($content), $query);
return $content;
}
示例2: foreach
echo Kohana::lang('search.results_for_pages');
?>
</h2>
<?php
if (count($data2) > 0) {
?>
<?php
foreach ($data2 as $row) {
?>
<div class="result-item">
<h3><?php
echo $row['heading'];
?>
</h3>
<p><?php
echo string::highlight(string::return_relevant($row['text'], $form['value']), $form['value']);
?>
</p>
<a href="/page/<?php
echo $row['url'];
?>
"><?php
echo Kohana::lang('search.more');
?>
</a>
</div>
<?php
}
} else {
?>
<p><?php