xxxxxxxxxx
<?php
$phone = preg_replace( '/\s+/', '', "01234 567890" );
echo $phone;
xxxxxxxxxx
<?php
$stripped = str_replace(' ', '', "10 1000 0000 000");
echo $stripped;
xxxxxxxxxx
$string = "this is my string";
$string = preg_replace('/\s+/', '', $string);
xxxxxxxxxx
phpCopy<?php
$searchString = " ";
$replaceString = "";
$originalString = "This is a programming tutorial";
$outputString = preg_replace('/\s+/', '', $originalString);
echo("The original string is: $originalString \n");
echo("The string without spaces is: $outputString \n");
?>
xxxxxxxxxx
<?php
$name = "Yeasin_ahammed_apon"
#str_replace('what u want to replace', 'with what ', $name);
str_replace('_', ' ', $name);
echo $name;
# output: Yeasin ahammed apon
?>
#str_replace('what u want to replace', 'with what ', $name);
xxxxxxxxxx
<?php
$string = "DelftStack is a best platform.....";
echo "Output: " . rtrim($string, ".");
?>
Output: DelftStack is a best platform
xxxxxxxxxx
phpCopy<?php
$searchString = " ";
$replaceString = "";
$originalString = "This is a programming tutorial";
$outputString = str_replace($searchString, $replaceString, $originalString);
echo("The original string is: $originalString \n");
echo("The string without spaces is: $outputString");
?>
xxxxxxxxxx
<?php
$mainstr = "@@PHP@Programming!!!.";
echo "Text before remove:\n" . $mainstr;
echo "\n\nText after remove: \n" . trim($mainstr, '@!.');
?>
xxxxxxxxxx
<?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));
?>
output:
Text before remove:
<h2>Welcome to <b>PHPWorld</b></h2>
Text after remove:
Welcome to PHPWorld