PHP trim() ফাংশন
উদাহরণ
স্ট্রিং উভয়দিকের চিহ্ন সরানো ("Hello"-এর "He" এবং "World"-এর "d!"-এর মতো):
<?php $str = "Hello World!"; echo $str . "<br>"; echo trim($str,"Hed!"); ?>
সংজ্ঞা ও ব্যবহার
trim() ফাংশন স্ট্রিং উভয়দিকের শূন্য অক্ষর বা অন্য প্রদত্ত চিহ্ন সরানো
সংশ্লিষ্ট ফাংশনসমূহ:
ভাষা
trim(s tring,charlist)
পারামিটার | বর্ণনা |
---|---|
string | অনিবার্য।পরীক্ষা করতে হলে চিহ্নিত স্ট্রিং |
charlist |
Optional. Specify which characters to remove from the string. If omitted, the following characters will be removed:
|
Technical Details
Return Value: | Returns the modified string |
PHP Version: | 4+ |
Update Log: | In PHP 4.1, a new feature was added: charlist Parameter. |
More Examples
Example 1
Remove spaces from both sides of the string:
<?php $str = " Hello World! "; echo "Without trim: " . $str; echo "<br>"; echo "Use trim: " . trim($str); ?>
The HTML output of the above code is as follows (please check the source code):
<!DOCTYPE html> <html> <body> Without trim: Hello World! <br>Use trim: Hello World! </body> </html>
The browser output of the above code is as follows:
Without trim: Hello World! Use trim: Hello World!
Example 2
Remove newline characters (\n) from both sides of the string:
<?php $str = "\n\n\nHello World!\n\n\n"; echo "Without trim: " . $str; echo "<br>"; echo "Use trim: " . trim($str); ?>
The HTML output of the above code is as follows (please check the source code):
<!DOCTYPE html> <html> <body> Without trim: Hello World! <br>Use trim: Hello World! </body> </html>
The browser output of the above code is as follows:
Without trim: Hello World! Use trim: Hello World!