1

How to remove/escape special charater fro the script

String's are

echo $position="marketing & executive cum \ stock ";

Outputs are: marketing & executive cum \ stock

But I want result after removing:

output: marketing executive cum stock

how it is posible ?

is there any solutions please help..

caisah
  • 1,701
  • 1
  • 19
  • 29
Anuveester
  • 87
  • 1
  • 1
  • 8
  • Possible duplicate of [Regular Expression Sanitize (PHP)](http://stackoverflow.com/questions/3022185/regular-expression-sanitize-php) – v010dya Mar 11 '17 at 10:19

3 Answers3

1

By using preg_replace() you can do this

function cleanString($string) {
   $string = str_replace(array( '(', ')' ), '', $string);
   return preg_replace('/[^A-Za-z0-9\-]/', ' ', $string); 
}

echo cleanString('marketing & executive cum \ stock ');
Muthu17
  • 1,241
  • 10
  • 17
1

Use Following

$position="marketing & executive cum \ stock ";

echo preg_replace('/[^A-Za-z0-9\-\(\) ]/', '', $position);
Karthik
  • 4,583
  • 12
  • 36
  • 65
0

This question is a possible duplicate of this Remove all special characters from a string So please remove this question

Community
  • 1
  • 1
Aravinth
  • 89
  • 3
  • 17