The following code filters html information such as htmlentities ().

Source: Internet
Author: User
In the following code, how to filter html such as htmlentities () is to filter the keyword, that is, to filter the search content entered by the user out of the html code, my younger brother doesn't know much about php. thanks for public & nbsp; function & nbsp; search () {global & how can I filter html such as htmlentities () in the following code?

It should be to filter the keyword, that is, to filter out the html code of the search content entered by the user
If you have trouble, give the code directly. The younger brother doesn't know much about php. thank you.
Public function search ()
{
Global $ _ FANWE;

$ Page_args = array (
'City _ PY' => CURRENT_CITY_PY,
'Sort '=> trim ($ _ FANWE ['request'] ['sort']),
'Keyword' => trim ($ _ FANWE ['request'] ['keyword']),
);

$ Keyword = '';
If (! Empty ($ page_args ['keyword'])
{
$ Page_args ['keyword'] = urldecode ($ page_args ['keyword']);
$ Keyword = & $ page_args ['keyword'];

$ Keyword_query = clearSymbol ($ page_args ['keyword']);
If (! Empty ($ keyword_query ))
{
$ Search_txt = clearRepeat ($ keyword_query );
$ Keyword_query = segmentToUnicode ($ keyword_query, '+ ');
$ Fields = ", MATCH (gm. content) AGAINST ('$ keyword_query') AS similarity ";
$ Where. = "where match (gm. content) AGAINST ('$ keyword_query' in boolean mode )";
}
Else
$ Keyword = '';
}

If (! Empty ($ keyword ))
{
$ Insert_sort = 'gk. cr_sort ASC ';

$ City_name = $ _ FANWE ['current _ City'] ['name'];

If (CURRENT_CITY_PY = CHINA_CITY_PY)
{
// When all city products are not included in the country
If ($ _ FANWE ['setting'] ['all _ City'] = 0)
{
$ Where. = "AND gk. city = '$ city_name '";
}
Else
$ Insert_sort = 'gk. r_sort ASC ';
}
Elseif (CURRENT_CITY_PY! = '')
{
// When the city shows the goods nationwide
If ($ _ FANWE ['setting'] ['index _ all'] = 1)
{
$ Fields. = ", (gk. city = '$ city_name') as is_now_city ";
$ Insert_sort = 'is _ now_city DESC, '. $ insert_sort;
$ Quanguo_name = $ _ FANWE ['cache'] ['city'] ['all'] [CHINA_CITY_PY] ['name'];
$ Where. = "AND gk. city IN ('$ city_name', '$ quanguo_name ')";
}
Else
{
$ Where. = "AND gk. city = '$ city_name '";
}
}

$ Order = '';
$ Sort = & $ page_args ['sort '];
$ Sort_array = array ('spa' => 'G. shop_price ASC ', 'spd' => 'g. shop_price DESC ', 'Eta' => 'gk. end_time ASC ', 'etd' => 'gk. end_time DESC ', 'cca' => 'g. click_count ASC ', 'ccd' => 'g. click_count DESC ', 'sa' => 'g. score ASC ', 'SD' =>' g. score DESC ', 'ba' =>' g. bought ASC ', 'bd' => 'g. bought DESC ', 'da' => 'discount ASC', 'DD' => 'discount desc ');

If (array_key_exists ($ sort, $ sort_array ))
$ Order = $ sort_array [$ sort];
Else
{
Unset ($ page_args ['sort ']);
$ Sort = '';
}

If (empty ($ order ))
$ Order. = 'similarity DESC, '. $ insert_sort.', gk. sort ASC, g. id ASC ';
Else
$ Order. = ', similarity DESC,'. $ insert_sort. ', gk. sort ASC, g. id DESC ';

$ Goods_count = DB: resultFirst ('SELECT COUNT (DISTINCT g. id)
FROM '. DB: table ('goods _ now_match'). 'AS gm
Inner join '. DB: table ('goods _ now_key'). 'AS gk ON gk. id = gm. id
Inner join '. DB: table ('goods _ now').' AS g ON g. id = gk. ID'. $ where );

$ Pager = buildPage ('Now/search', $ page_args, $ goods_count, $ _ FANWE ['Page'], 24 );

$ Res = DB: query ('select g. id, g. small_img, g. end_time, g. market_price, g. begin_time, g. shop_price,
Gk. city, gk. site_id, g. is_best, g. bought, g. name, g. sort, g. site_name, g. collect_buy, g. click_count,
G. url, g. collect_count, g. add_time, (g. shop_price/g. market_price) AS discount, g. post_count '. $ fields .'
FROM '. DB: table ('goods _ now_match'). 'AS gm
Inner join '. DB: table ('goods _ now_key'). 'AS gk ON gk. id = gm. id
Inner join '. DB: table ('goods _ now').' AS g ON g. id = gk. ID'. $ where .'
Order by '. $ order. 'limit'. $ pager ['limit']);

$ Goods_list = array ();


While ($ goods = DB: fetch ($ res ))
{
S ('goods')-> goodsFormat ($ Goods );
$ Goods_list [] = $ goods;
}
}

Include template ('Page/search_index ');

Display ();
}
Share:
------ Solution --------------------
If your code is okay! Just add a strip_tags function!
Public function search ()
{
Global $ _ FANWE;

$ Page_args = array (
'City _ PY' => CURRENT_CITY_PY,
'Sort '=> trim ($ _ FANWE ['request'] ['sort']),
'Keyword' => strip_tags (trim ($ _ FANWE ['request'] ['keyword']),
); // Add a strip_tags.

$ Keyword = '';
If (! Empty ($ page_args ['keyword'])

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.