How does the following code perform html filtering, 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 out the html code from 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 _ cit'] ['name']; if (CURRENT_CITY_PY = CHINA_CITY_PY) {// if ($ _ FANWE ['setting'] ['all _ City'] = 0) {$ where. = "AND gk. city = '$ city_name' ";} else $ insert_sort = 'gk. r_sort ASC ';} elseif (CURRENT_CITY_PY! = '') {// 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 gmINNER join '. DB: table ('goods _ now_key '). 'As gk ON gk. id = gm. idINNER JOIN '. DB: table ('goods _ right '). '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 gmINNER join '. DB: table ('goods _ now_key '). 'As gk ON gk. id = gm. idINNER JOIN '. DB: table ('goods _ right '). 'As g ON g. id = gk. ID '. $ where. 'order '. $ 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 ();}


Reply to discussion (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']) {$ 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 _ cit'] ['name']; if (CURRENT_CITY_PY = CHINA_CITY_PY) {// if ($ _ FANWE ['setting'] ['all _ City'] = 0) {$ where. = "AND gk. city = '$ city_name' ";} else $ insert_sort = 'gk. r_sort ASC ';} elseif (CURRENT_CITY_PY! = '') {// 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 gmINNER join '. DB: table ('goods _ now_key '). 'As gk ON gk. id = gm. idINNER JOIN '. DB: table ('goods _ right '). '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 gmINNER join '. DB: table ('goods _ now_key '). 'As gk ON gk. id = gm. idINNER JOIN '. DB: table ('goods _ right '). 'As g ON g. id = gk. ID '. $ where. 'order '. $ 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 ();}

$ String = preg_replace ("'<[\/\!] *? [^ <>] *?> 'Si "," ", $ string );

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.