function
set_arr_keyword_red(
$info_arr
,
$search_arr
)
{
foreach
(
$search_arr
as
$search_str
)
{
foreach
(
$info_arr
as
$key
=>
$info
)
{
if
(in_array(
$key
,
array
(
'item_title'
,
'keywords'
,
'photo_title'
,
'photo_site'
,
'content'
,)))
{
$info
=
strip_tags
(
$info
);
$info
=
str_replace
(
' '
,
''
,
$info
);
$q_str_pos
=
stripos
(
$info
,
$search_str
);
if
(false!==
$q_str_pos
)
{
$info
= csubstr(
$info
,
$q_str_pos
+150);
$temp
= csubstr(
$info
,
$q_str_pos
-150);
$info
=
substr
(
$info
,
strlen
(
$temp
), 300);
$info
= preg_replace(
"/{$search_str}/i"
,
"<font color='red'>{$search_str}</font>"
,
$info
);
if
(
$info_arr
[
'match_key'
]==
''
)
$info_arr
[
'match_key'
] =
$key
;
}
else
{
$info
= csubstr(
$info
,300);
}
}
$info_arr
[
$key
] =
$info
;
}
}
return
$info_arr
;
}
$str
=
'woloveu小君'
;
$info_arr
=
array
(
'photo_title'
=>
'womejiojd我们都围殴防静低屁啊小君鸡冻啊泡脚盆大'
);
$search_arr
=
array
(
'小君'
);
$ret
= set_arr_keyword_red(
$info_arr
,
$search_arr
);
dump(
$ret
);