1phpCopy<?php
2function RemoveSpecialChar($str)
3{
4 $res = preg_replace('/[0-9\@\.\;\" "]+/', '', $str);
5 return $res;
6}
7$str = "My name is hello and email hello.world598@gmail.com;";
8$str1 = RemoveSpecialChar($str);
9echo "My UpdatedString: ", $str1;
10?>
11
1phpCopy<?php
2$str = "@@HelloWorld";
3$str1 = substr($str, 1);
4echo $str1 . "\n\n";
5$str1 = substr($str, 2);
6echo $str1;
7?>
8
1phpCopy<?php
2$mainstr = "<h2>Welcome to <b>PHPWorld</b></h2>";
3
4echo "Text before remove: \n" . $mainstr;
5
6echo "\n\nText after remove: \n" .
7 str_ireplace(array('<b>', '</b>', '<h2>', '</h2>'), '',
8 htmlspecialchars($mainstr));
9?>
10
1phpCopy<?php
2$mainstr = "@@PHP@Programming!!!.";
3echo "Text before remove:\n" . $mainstr;
4echo "\n\nText after remove: \n" . trim($mainstr, '@!.');
5?>
6
1phpCopy<?php
2$string = "DelftStack is a best platform.....";
3echo "Output: " . rtrim($string, ".");
4?>
5
1phpCopy<?php
2$mainstr = "This is a sim'ple text;";
3echo "Text before remove: \n" . $mainstr, "\n";
4$replacestr = remove_sp_chr($mainstr);
5function remove_sp_chr($str)
6{
7 $result = str_replace(array("#", "'", ";"), '', $str);
8 echo "\n\nText after remove: \n" . $result;
9}
10?>
11
1phpCopy<?php
2$str = "ei all, I said eello";
3//$trans = array("h" => "-", "hello" => "hi", "hi" => "hello");
4echo "Output: " . strtr($str, "e", "h");
5?>
6
1phpCopy<?php
2$strTemplate = "My name is :name, not :name2.";
3$strParams = [
4 ':name' => 'Dave',
5 'Dave' => ':name2 or :password',
6 ':name2' => 'Steve',
7 ':pass' => '7hf2348', ];
8echo "\n" . strtr($strTemplate, $strParams) . "\n";
9echo "\n" . str_replace(array_keys($strParams), array_values($strParams), $strTemplate) . "\n";
10
11
12?>
13