Q:

How to remove white space from a string in PHP

0

How to remove white space from a string in PHP

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the PHP trim() function

You can use the PHP trim() function to remove whitespace including non-breaking spaces, newlines, and tabs from the beginning and end of the string. It will not remove whitespace occurs in the middle of the string. Let's take a look at an example to understand how it basically works:

<?php
$my_str = '    Welcome to Tutorial Republic ';
echo strlen($my_str); // Outputs: 33
 
$trimmed_str = trim($my_str);
echo strlen($trimmed_str); // Outputs: 28
?>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP  and MySQL Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to find number of characters in a string in PH... >>
<< How to write comments in PHP...