functionclean($string){$string=str_replace(' ','-',$string);// Replaces all spaces with hyphens.returnpreg_replace('/[^A-Za-z0-9-]/','',$string);// Removes special chars.}
phpCopy<?phpfunctionRemoveSpecialChar($str){$res=preg_replace('/[0-9@.;" "]+/','',$str);return$res;}$str="My name is hello and email hello.world598@gmail.com;";$str1=RemoveSpecialChar($str);echo"My UpdatedString: ",$str1;?>
functionremoveSpecialChar($string){$string=strtolower($string);$string=preg_replace('/[^da-z ]/i','',$string);// Removes special chars.$string=str_replace(' ','-',$string);// Replaces all spaces with underscore.returnstrtolower($string);}
phpCopy<?php$mainstr="<h2>Welcome to <b>PHPWorld</b></h2>";echo"Text before remove:
".$mainstr;echo"
Text after remove:
".str_ireplace(array('<b>','</b>','<h2>','</h2>'),'',htmlspecialchars($mainstr));?>
phpCopy<?php$mainstr="This is a sim'ple text;";echo"Text before remove:
".$mainstr,"
";$replacestr=remove_sp_chr($mainstr);functionremove_sp_chr($str){$result=str_replace(array("#","'",";"),'',$str);echo"
Text after remove:
".$result;}?>
phpCopy<?php$strTemplate="My name is :name, not :name2.";$strParams=[':name'=>'Dave','Dave'=>':name2 or :password',':name2'=>'Steve',':pass'=>'7hf2348',];echo"
".strtr($strTemplate,$strParams)."
";echo"
".str_replace(array_keys($strParams),array_values($strParams),$strTemplate)."
";?>