remove from string php – How to Remove Special Character from String in PHP?

remove from string php Using substr function, Using substr_replace function, Using mb_substr function, Using rtrim function and remove special characters from string php

remove from string php

Use the PHP rtrim() function

<?php
$readme = 'Welcome itsolutionstuck!    ';
echo strlen($readme);
 
$trimmed_str = rtrim($readme);
echo strlen($trimmed_str);
?>

Don’t Miss : check file exists in php

Using substr_replace function

<?Php
$message = "Welcome itsolutionstuck!";
echo "Default string: " . $message . "\n";
 
echo "Latest string: " . substr_replace($message ,"",-1) . "\n";
?>

Using substr function

<?php
$message = "Welcome itsolutionstuck!";
echo "Default string: " . $message . "\n";
 
echo "Latest string: " . substr($message, 0, -1) . "\n";
?>

Using mb_substr function

<?php
$message = "Welcome itsolutionstuck!";
echo "Default string: " . $message . "\n";
 
echo "Latest string: " . mb_substr($message, 0, -1) . "\n";
?>

Using rtrim function

<?php
$message = "Welcome itsolutionstuck!";
echo "Default string: " . $message . "\n";
 
echo "Latest string: " . rtrim($message, "!") . "\n";
?>

See also :  Advantages of php - Top 10 Fundamental PHP Advantages And Disadvantages

Leave a Reply

Your email address will not be published.