Simple PHP trim function full code

Click to rate this tutorial!
[Total: 1 Average: 5]

Just a simple trim function with full code. Trim functions are used in many areas and this will be a handy tutorial to give you a bigger picture of what trim actually does. Trim usually Strip whitespace (or other characters) from the beginning and end of a string

Below is a simple html form that post some data to a php script[trim.php]

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Simple Trim Function Using PHP</title>
</head>
<body>
<form action="trim.php" method="post">
Type any thing <input type="text" name="word"/>
<input name="submit" type="submit" value="Length"/>
</form>
</body>
</html>

For example i have inserted a word “Welcome To PHP” inside the text field above.
Now let us see how trim.php script looks like.

<?php
$word=$_POST['word'];
 echo trim($word,"Welcome");
?>

Find out yourself what the output will be once you run the script. Have a good one. 🙂

Click to rate this tutorial!
[Total: 1 Average: 5]

Leave a Reply

Your email address will not be published.