I made this simple function to filter the data. I add the symbols that I allow to be included but I dont know how to add / symbol as well
public function filter($text)
{
return preg_replace('/[^^a-zA-Z0-9#@:_(),.!@" ]/','',$text);
}
When preg_replace() is called with the /e modifier, the interpreter must parse the replacement string into PHP code once for every replacement made, while preg_replace_callback() uses a function that only needs to be parsed once.
preg_split () in PHP – this function is used to perform a pattern match on a string and then split the results into a numeric array preg_replace () in PHP – this function is used to perform a pattern match on a string and then replace the match with the specified text.
preg_replace () in PHP – this function is used to perform a pattern match on a string and then replace the match with the specified text. Below is the syntax for a regular expression function such as PHP preg_match (), PHP preg_split () or PHP preg_replace (). <?php function_name ('/pattern/',subject); ?>
$pattern: This parameter contains the string element which is used to search the content and it can be a string or array of string. $replacement: It is mandatory parameter which specifies the string or an array with strings to replace.
You can either escape it with a backslash:
preg_replace('/\//' ...);
Or use other characters as delimiters:
preg_replace('|/|' ...);
Simply escape the character with a backslash.
public function filter($text)
{
return preg_replace('/[^^a-zA-Z0-9#@:_(),.!@"\/ ]/','',$text);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With