Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

escape special character from string in php

Tags:

arrays

php

mysql

we are trying to escape some special character from our string please tell me the function that we have to use e.g. HTC Desire 210 – White
In this example we escape -(hyphen) special character. In above example we have lot of product name with different different special character that we escape it. thanks for your co-operation.

like image 720
Gopal Avatar asked May 25 '26 08:05

Gopal


1 Answers

Pass string in this function.

function clean($string){
   $string = str_replace(' ', '-', $string); // Replaces spaces with hyphens.
   return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
}

For more info, check this Remove Special Character - Stackoverflow

like image 181
Nana Partykar Avatar answered May 27 '26 22:05

Nana Partykar