Skip to content

Instantly share code, notes, and snippets.

@paulund
Last active December 18, 2015 23:19
Show Gist options
  • Save paulund/5861136 to your computer and use it in GitHub Desktop.
Save paulund/5861136 to your computer and use it in GitHub Desktop.
Examples of using multiple trim functions with PHP
<?php
$string = ' This is an example string ';
echo ltrim($string); // This is display the text This is an example string .
?>
<?php
$string = ' This is an example string ';
echo rtrim($string); // This is display the text This is an example string.
?>
<?php
$string = ' This is an example string ';
echo trim($string); // This is display the text This is an example string.
?>
<?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