How do I deal with quotes here?
What i want is /[^a-zA-Z0-9-_.,!()'\/"]/ but how do i deal the quotes?

$pattern = '/[^a-zA-Z0-9-_.,!()'"\/' . $whatever . ']/';
return preg_replace($pattern, '',  $value);

Cheers!

Hi pritaeas , thank you.
I understand that but how do i combine escape both for php and preg_replace?

For the backslash it would look like this:

preg_match('%[^a-zA-Z0-9-_.,!()\'"\\\\/]%s', $subject)

As mentioned in the first note in the first link, first escape for the regex, and then for the php string.

Sorry for not really understanding ...
so a single backslash will escape single quote for php in this case and preg_match won't bother with it?

Thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.