PDA

View Full Version : برش رشته بعد از کیورد در php



artablog
سه شنبه 16 خرداد 1396, 10:06 صبح
سلام
قسمت جستجوی سایت سورس فرج رو ببینید

https://sourceforge.net/directory/os:windows/?q=Simple+script مثال :

وقتی کلمه ایی رو جستجو میکنیم از کیورد پیدا شده تا x مقدار از رشته برش داده میشه و کیورد هم بولد میشه من یه تابعی نوشتم


function smarty_modifier_neatest_trim($txt,$q, $len = 250, $start_tag = '<strong>', $end_tag = '</strong>') { $txt = strip_tags($txt); $txt = str_replace(array("\n\r","\r\n","\n","\r","\t"), ' ', $txt); $txt = trim($txt); $txt = preg_replace('/\s+/', ' ', $txt); if( mb_strlen($txt, 'UTF-8') > $len ) { $txt = mb_substr($txt, 0, $len, 'UTF-8') . "..."; } $query = $q; $query = str_replace(array('(',')','+','-','~','>','<'), array('','','','','','',''), $query);
$query = str_replace( array('\\', '^', '$', '.', '[', '|', '?', '*', '{', '}', '/', ']'), array('\\\\', '\\^', '\\$', '\\.', '\\[', '\\|', '\\?', '\\*', '\\{', '\\}', '\\/', '\\]'), $query); $query = preg_replace('/\s+/', ' ', $query); $words = array(); if(preg_match_all('/"([^"]*)"/', $query, $matches)) { $l = count($matches[1]); for($k=0;$k<$l;$k++) { $words[] = $matches[1][$k]; } } $query = trim(preg_replace('/\s+/', ' ', preg_replace('/"([^"]*)"/', '', $query))); $words = array_merge($words, explode(" ", $query));
foreach($words as $word) { if($word!='') { $txt = preg_replace("/(\PL|\s+|^)($word)(\PL|\s+|$)/i", "$01" . $start_tag . "$02". $end_tag . "$03", $txt); } } return $txt;}

تقریبا مثل اون عمل میکنه ولی یه سری تغییراتی باید بدم که دقیقا مثل اون باشه از اساتید میخوام کمک کنن مرسی