| Viewed 108 times

How to remove space in PHP


How to remove space in PHP

PHP
1 Answer
Mohammad Qandeel
Answered
4

In case you want to delete the spaces from a string in PHP
These functions can be used to delete or strip spaces

  • trim()
  • rtrim()
  • ltrim()
  • str_replace()

 

You have this " How are You " and you want to delete the spaces from the beginning and the end of the string  using trim() function

Example

<?php
    $string   =" How are You ";
    $newString=trim($string);
?>

the new string will be "How are You" 

To delete all the spaces from the string we use str_replace() function

Example

<?php
    $string   =" How are You ";
    $newString=$newString=str_replace(' ', '',$string);
?>

the new string will be "HowareYou"