The original string:
hello world
with the whitespace trimmed trim(string):
hello world

The original string:
cats
with the letter s trimmed using trim(string,s):
cat

The original string:
chip lady
with the letters c and y trimmed using trim(string,cy):
hip lad

The original string:
hi class
with the letters c and y trimmed using trim(string,hs):
i cla

The original string:
abc
with the letters bad trimmed using trim(string,bad):
c

 

Code for above example

 

<?php

$original_string1 = ' hello World ';
//this will trim the whitespace
$trimmed_string1 = trim($original_string1);

$original_string2 = 'cats';
//We can also trim letters
$trimmed_string2 = trim($original_string2, 's');

//we can trim more than one letter
$original_string3 = 'chip lady';
$trimmed_string3 = trim($original_string3,'cy');


// but be aware of this
$original_string4 = 'hi class';
$trimmed_string4 = trim($original_string4,'hs');

 


// AND this
$original_string5 = 'abc';
$trimmed_string5 = trim($original_string5,'bad');




echo "
<p>
The original string:<br />
$original_string1<br />
with the whitespace trimmed trim(string):<br />
$trimmed_string1
</p>";

echo "
<p>
The original string:<br />
$original_string2<br />
with the letter s trimmed using trim(string,s):<br />
$trimmed_string2
</p>";

echo "
<p>
The original string:<br />
$original_string3<br />
with the letters c and y trimmed using trim(string,cy):<br />
$trimmed_string3
</p>";

echo "
<p>
The original string:<br />
$original_string4<br />
with the letters c and y trimmed using trim(string,hs):<br />
$trimmed_string4<br />
</p>";

?>