Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to remove extra white spaces from string using PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 116
    Comment on it

    Hello Reader's! if you are dealing with excess whitespace on the beginning or end of the string then you can use trim(), ltrim() or rtrim() to remove them. Also If have to delete extra spaces within a string consider a preg_replace() of multiple whitespaces " "* with a single whitespace " ".

    Let's see and example below:-

    $str = trim(preg_replace('/\s+/',' ', $str));
    

    Or you can also use:-

    $productID=preg_replace('/[\s]+.*/','',$productID);
    

    Now the new $str and $productID will have no more spaces left.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: