string trim function - removes whitespace(s) or space character(s) from the beginning & end of a string
string-trim-function-example-in-php.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>string trim function - removes whitespace(s) or space character(s) from the beginning & end of a string</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Md Iqbal Hosan">
<meta name="title" content="string trim function - removes whitespace(s) or space character(s) from the beginning & end of a string">
<meta name="keywords" content="php, example, code, array, function, trim, string">
<meta name="description" content="string trim function - removes whitespace(s) or space character(s) from the beginning & end of a string">
<style>
h2, h4{background:#eee; color:#000072;}
h2{ padding:3px; margin:3px; font-size:21px;}
h4{ padding:2px; margin:2px; font-size:17px;}
p{padding:2px; margin:2px; color:#0099CC;}
body{ background:#FFFFFa;}
</style>
</head>
<body>
<h2>string trim function - removes whitespace(s) or space character(s) from the beginning & end of a string</h2>
<pre>
<?php
/*
-----------------------------------------------------------------
let us make a string holding whitespaces at the beginning & end
-----------------------------------------------------------------
*/
$whitespaceedString = " this is a whitespaceed string.\t\t";
echo "<h4>Output of whitespaceed String</h4>";
print "<p>$"."whitespaceedString = {$whitespaceedString}</p>";
print "<p>string length : ".strlen($whitespaceedString)."</p>";
/*
---------------------------------------------------------------------------------------------
we want to remove the whitespace at the beginning & end of the string by using trim function
---------------------------------------------------------------------------------------------
*/
$spaceRemovedString = trim($whitespaceedString);
echo "<h4>Output of spaceRemovedString by using string trim function</h4>";
print "<p>$"."spaceRemovedString = {$spaceRemovedString}</p>";
print "<p>string length : ".strlen($spaceRemovedString)."</p>";
/*
---------------------------------------------------------------------------------------
this function rapidly used in professional programming to remove space and whitespaces
---------------------------------------------------------------------------------------
*/
?>
</pre>
</body>
</html>

No comments:
Post a Comment
leave your comments here..