Last active
December 18, 2015 23:19
-
-
Save paulund/5861136 to your computer and use it in GitHub Desktop.
Examples of using multiple trim functions with PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$string = ' This is an example string '; | |
echo ltrim($string); // This is display the text This is an example string . | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$string = ' This is an example string '; | |
echo rtrim($string); // This is display the text This is an example string. | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$string = ' This is an example string '; | |
echo trim($string); // This is display the text This is an example string. | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$pattern = '/\s*/m'; | |
$replace = ''; | |
$testString = 'Here is some test text'; | |
$removedWhitespace = preg_replace( $pattern, $replace,$testString ); | |
$removedWhitespace2 = str_replace (' ', '', $testString); | |
echo $removedWhitespace; | |
echo $removedWhitespace2; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment