테스트 사이트 - 개발 중인 베타 버전입니다

태그가 검색되지 않게 하는 방법 채택완료

Eltan 11년 전 조회 4,132
검색을 하면 태그 명령어가 검색이 됩니다.
 
 
 
예를 들어, 글 내용이 "안녕하세요" 라고 친다면 
 
검색어에 font를 넣으면 위의 "안녕하세요"가 검색되어 나옵니다. RED로 검색해도 마찬가지고요.
 
즉, html까지 검색해서 뿌려주는 거지요.
 
그래서 사용자가 보기엔 엉뚱한 내용이 검색되어 나오는 것처럼 보입니다.
 
 
 
질문과 답변 보면 검색 시 태그가 보이지 않게 하는 방법은 많더군요. strip_tags와 같은...
 
하지만 제가 원하는 건 태그를 검색하지 않는 방법입니다.
 
혹시 답을 알고 있으신 분이 계실까요?
 
 
 
 
 
댓글을 작성하려면 로그인이 필요합니다.

답변 1개

채택된 답변
+20 포인트
mysql 에는 strip_tags 같은 함수가 존재하지 않습니다.
사용자정의 함수를 만들어서 조건절을 만들어야 합니다.
http://search.mysql.com/search?site=refman-%35%31&q=DROP" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">DROP http://search.mysql.com/search?site=refman-%35%31&q=FUNCTION" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">FUNCTION http://dev.mysql.com/doc/refman/5.1/en/control-flow-functions.html" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">IF http://search.mysql.com/search?site=refman-%35%31&q=EXISTS" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">EXISTS strip_tags||http://search.mysql.com/search?site=refman-%35%31&q=CREATE" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">CREATE http://search.mysql.com/search?site=refman-%35%31&q=FUNCTION" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">FUNCTION strip_tags( http://dev.mysql.com/doc/refman/5.1/en/analysing-spatial-information.html" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">x http://search.mysql.com/search?site=refman-%35%31&q=LONGTEXT" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">longtext) http://search.mysql.com/search?site=refman-%35%31&q=RETURNS" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">RETURNS http://search.mysql.com/search?site=refman-%35%31&q=LONGTEXT" style="color: #474747; text-decoration: none; -webkit-box-shadow: none !important">longtexthttp://search.mysql.com/search?site=refman-%35%31&q=LANGUAGE%20SQL" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">LANGUAGE SQL http://dev.mysql.com/doc/refman/5.1/en/non-typed-operators.html" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">NOT http://search.mysql.com/search?site=refman-%35%31&q=DETERMINISTIC" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">DETERMINISTIC http://search.mysql.com/search?site=refman-%35%31&q=READS%20SQL%20DATA" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">READS SQL DATAhttp://search.mysql.com/search?site=refman-%35%31&q=BEGIN" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">BEGINhttp://search.mysql.com/search?site=refman-%35%31&q=DECLARE" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">DECLARE sstart http://search.mysql.com/search?site=refman-%35%31&q=INT" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">INT http://search.mysql.com/search?site=refman-%35%31&q=UNSIGNED" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">UNSIGNED;http://search.mysql.com/search?site=refman-%35%31&q=DECLARE" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">DECLARE ends http://search.mysql.com/search?site=refman-%35%31&q=INT" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">INT http://search.mysql.com/search?site=refman-%35%31&q=UNSIGNED" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">UNSIGNED;http://search.mysql.com/search?site=refman-%35%31&q=SET" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">SET sstart = http://dev.mysql.com/doc/refman/5.1/en/string-functions.html" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">LOCATE('<', http://dev.mysql.com/doc/refman/5.1/en/analysing-spatial-information.html" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">x, 1);http://dev.mysql.com/doc/refman/5.1/en/string-functions.html" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">REPEAThttp://search.mysql.com/search?site=refman-%35%31&q=SET" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">SET ends = http://dev.mysql.com/doc/refman/5.1/en/string-functions.html" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">LOCATE('>', http://dev.mysql.com/doc/refman/5.1/en/analysing-spatial-information.html" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">x, sstart);http://search.mysql.com/search?site=refman-%35%31&q=SET" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">SET http://dev.mysql.com/doc/refman/5.1/en/analysing-spatial-information.html" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">x = http://dev.mysql.com/doc/refman/5.1/en/string-functions.html" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">CONCAT(http://dev.mysql.com/doc/refman/5.1/en/string-functions.html" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">SUBSTRING( http://dev.mysql.com/doc/refman/5.1/en/analysing-spatial-information.html" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">x, 1 ,sstart -1) ,http://dev.mysql.com/doc/refman/5.1/en/string-functions.html" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">SUBSTRING(http://dev.mysql.com/doc/refman/5.1/en/analysing-spatial-information.html" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">x, ends +1 )) ;http://search.mysql.com/search?site=refman-%35%31&q=SET" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">SET sstart = http://dev.mysql.com/doc/refman/5.1/en/string-functions.html" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">LOCATE('<', http://dev.mysql.com/doc/refman/5.1/en/analysing-spatial-information.html" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">x, 1);UNTIL sstart < 1 http://dev.mysql.com/doc/refman/5.1/en/control-flow-functions.html" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">END http://dev.mysql.com/doc/refman/5.1/en/string-functions.html" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">REPEAT;return http://dev.mysql.com/doc/refman/5.1/en/analysing-spatial-information.html" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">x;http://dev.mysql.com/doc/refman/5.1/en/control-flow-functions.html" style="color: #0d66ac; text-decoration: none; -webkit-box-shadow: none !important">END;

select * from 테이블 where strip_tags(필드) like '%검색어%' 
위와 같은 방법으로 응용해서 코드를 짜야하는데.. 추천하고 싶지는 않네요.
출처 : http://www.sitepoint.com/forums/showthread.php?656167-PHP-s-strip_tags()-equivalent-MYSQL-function
로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인