xxxxxxxxxx
phpCopy<?php
$str = "ei all, I said eello";
//$trans = array("h" => "-", "hello" => "hi", "hi" => "hello");
echo "Output: " . strtr($str, "e", "h");
?>
xxxxxxxxxx
function clean($string) {
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
}
xxxxxxxxxx
phpCopy<?php
function RemoveSpecialChar($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;
?>
xxxxxxxxxx
<?php
function RemoveSpecialChar($str)
{
$res = preg_replace('/[0-9\@\&\^\%\(\)\#\$\!\]\[\}\{\*\'\"\.\;\" "]+/', ' ', $str);
return $res;
}
$str = "My name is hello and)(**&&^%$$#@! em[ail he}ll'o.world{59}8@gmail.com;";
$str1 = RemoveSpecialChar($str);
echo $str1;
?>
xxxxxxxxxx
function removeSpecialChar($string)
{
$string = strtolower($string);
$string = preg_replace('/[^\da-z ]/i', '', $string);// Removes special chars.
$string = str_replace(' ', '-', $string); // Replaces all spaces with underscore.
return strtolower($string);
}
xxxxxxxxxx
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;
}
?>
xxxxxxxxxx
phpCopy<?php
$str = "@@HelloWorld";
$str1 = substr($str, 1);
echo $str1 . "\n\n";
$str1 = substr($str, 2);
echo $str1;
?>
xxxxxxxxxx
phpCopy<?php
$mainstr = "<h2>Welcome to <b>PHPWorld</b></h2>";
echo "Text before remove: \n" . $mainstr;
echo "\n\nText after remove: \n" .
str_ireplace(array('<b>', '</b>', '<h2>', '</h2>'), '',
htmlspecialchars($mainstr));
?>
xxxxxxxxxx
phpCopy<?php
$str = "geeks";
$str = ltrim($str, 'g');
echo $str;
?>
xxxxxxxxxx
phpCopy<?php
$string = "DelftStack is a best platform.....";
echo "Output: " . rtrim($string, ".");
?>
xxxxxxxxxx
phpCopy<?php
$mainstr = "@@PHP@Programming!!!.";
echo "Text before remove:\n" . $mainstr;
echo "\n\nText after remove: \n" . trim($mainstr, '@!.');
?>