บทความ > PHP

PHP split multiple condition Turn Back

เมื่อ 2017-07-26 16:33:04

Split word by space or plus character to array.

$arr = preg_split("/[s,+]/", trim($_GET['text_search']));

 

And call function markWord for replace hightlight styles.

function markWord($arr,$str)
{   
$x = sizeof($arr);
for($i=0;$i<count($arr);$i++)
{
      $mul = ($i+1)/$x;
      $str = str_replace($array[$i],'<span style="background-color: '.rand_color($mul).'">'.$array[$i].'</span>',$str);
}
return $str;
}
Turn Back

Automotive ดูทั้งหมด

IT Update ดูทั้งหมด