php strip out special characters
function clean($string) {
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
}
php strip out special characters
function clean($string) {
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
}
Remove Special Character in PHP
phpCopy<?php
$str = "@@HelloWorld";
$str1 = substr($str, 1);
echo $str1 . "\n\n";
$str1 = substr($str, 2);
echo $str1;
?>
Remove Special Character in PHP
phpCopy<?php
$str = "geeks";
$str = ltrim($str, 'g');
echo $str;
?>
Remove Special Character in PHP
phpCopy<?php
$mainstr = "This is a sim'ple text;";
echo "Text before remove: \n" . $mainstr, "\n";
$replacestr = remove_sp_chr($mainstr);
function remove_sp_chr($str)
{
$result = str_replace(array("#", "'", ";"), '', $str);
echo "\n\nText after remove: \n" . $result;
}
?>
Remove Special Character in PHP
phpCopy<?php
$str = "ei all, I said eello";
//$trans = array("h" => "-", "hello" => "hi", "hi" => "hello");
echo "Output: " . strtr($str, "e", "h");
?>
Remove Special Character in PHP
phpCopy<?php
$strTemplate = "My name is :name, not :name2.";
$strParams = [
':name' => 'Dave',
'Dave' => ':name2 or :password',
':name2' => 'Steve',
':pass' => '7hf2348', ];
echo "\n" . strtr($strTemplate, $strParams) . "\n";
echo "\n" . str_replace(array_keys($strParams), array_values($strParams), $strTemplate) . "\n";
?>
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us