-2

Below is my code in javascript that remove special character using regex.

var yourInput = "string here";
re = /[`~!@$%^&*()+\=;'",.<>\{\}\[\]\\\/]/gi;
var isSplChar = re.test(yourInput);
if(isSplChar)
{
    var no_spl_char = yourInput.replace(/[`~!@$%^&*()+\;'",.<>\{\}\[\]\\\/]/gi, '');
    $(this).val(no_spl_char);
}

i want similiar version for php i tried below code but i gives error

$input_lines="string here";
preg_replace("/[`~!@$%^&*()+\;'",.<>\{\}\[\]\\\/]/", "", $input_lines);

what am i missing

mydeve
  • 553
  • 1
  • 14
  • 39

1 Answers1

0

You need to escape the " char and to change your delimiters :

preg_replace("~[`\~!@$%^&*()+\;'\",.<>\{\}\[\]\\\/]~", "", $input_lines);
Clorichel
  • 1,940
  • 1
  • 13
  • 24
  • i get Warning: preg_replace(): Unknown modifier ']' – mydeve Feb 01 '17 at 19:49
  • then you should change your delimiters, escaping `/` does not seem to be enough to PHP, I'm not sure why... just edited my answer with a working code :) – Clorichel Feb 01 '17 at 21:13