preg_replace('/[^A-Za-z0-9]/', "", $data)
<?php
$string = "DelftStack is a best platform.....";
echo "Output: " . rtrim($string, ".");
?>
Output: DelftStack is a best platform
<?php
$mainstr = "@@PHP@Programming!!!.";
echo "Text before remove:
" . $mainstr;
echo "
Text after remove:
" . trim($mainstr, '@!.');
?>
<?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));
?>
output:
Text before remove:
<h2>Welcome to <b>PHPWorld</b></h2>
Text after remove:
Welcome to PHPWorld
<?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) . "
";
?>
Output:
My name is Dave, not Steve.
My name is Steve or 7hf2348word, not Steve or 7hf2348word2.