PHP: <?php /** * * Hidden Statistics for external resources * .........................version 1.2.2 * * Developer: CyberX * License: MIT * */ // Main config require_once('./core/struct/DataBase.php'); require_once('./private/config.php'); // Structures require_once('./core/libraries/DBX.php'); require_once('./core/libraries/Cipher.php'); require_once('./core/libraries/SafeHTML.php'); require_once('./private/config.php'); $dbConfig = file_get_contents($_SERVER["DOCUMENT_ROOT"] .'/private/db_config.ini', true); /* Check installation */ if( strlen($dbConfig) > 0 ) { $cipher = new Cipher(); $safe = new SafeHTML(); $dbx_data = explode('|', $cipher::crypt('decrypt', $dbConfig)); // get database engine API $dbx = new DBX($dbx_data); $query = []; if( !empty($_GET['query']) ) { $query_string = $safe::safe($_GET['query']); // QUERY PATTERN FIELDS $query['field_route']['value'] = ''; $query['field_title']['value'] = ''; $query['field_description']['value'] = ''; $query['field_content']['value'] = $query_string; $dbx::query('q', 'revolver__nodes', $query); $search_query_result = $dbx::$result['result']; $output = '<div class="revolver__search_results"><ul>'; foreach ($search_query_result as $k => $v) { $output .= '<li><a href="'. $v['field_route'] .'" title="'. $v['field_description'] .'">'. $v['field_title'] .'</a><span>'. $v['field_description'] .'</span>'; $replace = trim(preg_replace('/ +/', ' ', preg_replace('/[^A-Za-z0-9 ]/', ' ', urldecode(strip_tags(html_entity_decode(strip_tags(preg_replace('/<[^>]*>/','',str_replace(array(" ","\n","\r"),"",html_entity_decode($v['field_content'], ENT_QUOTES,'UTF-8')))))))))); $snippet = preg_split("/". $query_string ."/i", $replace); $counter = 1; foreach ($snippet as $snip) { $length = ( (int)strlen( $snip ) / 100) * 30; if( $counter % 2 !== 0 ) { $highlight_1 = substr($snip, $length, 0); } else { $highlight_2 = substr($snip, 0, $length); } $counter++; } $output .= '<dfn style="display:block; margin-bottom: 10px;">... '. $highlight_1 . $query_string . $highlight_2 .' ...</dfn></li>'; } $output .= '</ul><p>Search for <b>'. $query_string .'</b>.</p></div>'; print $output; } else { print '<div class="revolver__search_results"><p>Empty query</p></div>'; } } ?> Конкретно вот здесь приходится два раза делать одно и то же(почему так?). PHP: $replace = trim(preg_replace('/ +/', ' ', preg_replace('/[^A-Za-z0-9 ]/', ' ', urldecode(strip_tags(html_entity_decode(strip_tags(preg_replace('/<[^>]*>/','',str_replace(array(" ","\n","\r"),"",html_entity_decode($v['field_content'], ENT_QUOTES,'UTF-8')))))))))); спасибо!