In PHP to filter some special characters or illegal characters we can have a lot of ways, like the regular expression str_replace is a good way, like a carriage return, space, line can be used to solve.
The nearly responsible system module is finally close to the end, the rest of the work is to match the testing and modification of the test.
While this relatively idle time, secretly write a few blog posts to record the time of the problem and my solution (or say the solution to it).
Well, the nonsense is not much to say, get into the chase.
There is a general need to go to the thief program, such as the removal of the original page link or something. However, I encountered is to export the development of the page to Word, security needs to remove the JS code block.
First on the code
The code is as follows |
Copy Code |
$searchRegex = Array ( '/(s*.*?s*)/I ',//Hyperlink '//i ',//JS script code ); $REPLACESTR = Array ( ' $ ', '' ); $content = Preg_replace ($searchRegex, $REPLACESTR, $content); |
PHP words This is relatively simple, is the use of preg_replace this function, not much to say ... It is important to note that there are two regular bars.
The code is as follows |
Copy Code |
$regexForLink = '/(s*.*?s*)/I '; Hypertext links $regexForJS = '//i '; JS script code |
If you want to filter HTML code, spaces, carriage return line breaks
The code is as follows |
Copy Code |
function deletehtml ($STR) { $str = Trim ($STR); $str = Strip_tags ($str, ""); $str = ereg_replace ("T", "", $str); $str = ereg_replace ("rn", "", $str); $str = Ereg_replace ("R", "", $str); $str = Ereg_replace ("n", "", $str); $str = Ereg_replace ("", "" ", $str); Return trim ($STR); }
|
Filtering all HTML tags in HTML can use the Strip_tags () function to strip HTML, XML, and PHP tags.
Strip_tags (String,allow)
Well, that's all, I hope it helps next time.
http://www.bkjia.com/PHPjc/633113.html www.bkjia.com true http://www.bkjia.com/PHPjc/633113.html techarticle in PHP to filter some special characters or illegal characters we can have a lot of ways, like the regular expression str_replace is a good way, like a carriage return, space, line can be used it ...