Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2011
    Posts
    69
    Thanks
    6
    Thanked 0 Times in 0 Posts

    remove more then 1 spaces from string

    Hi,

    I have a variable which returning a string with more then 1 spaces like this (<p> This is a test string from a variable </p>)


    I need to use a php function which can remove all extra spaces like this (<p> This is a test string from a variable</p>)


    regards

  • #2
    Regular Coder bacterozoid's Avatar
    Join Date
    Jun 2002
    Location
    USA
    Posts
    490
    Thanks
    24
    Thanked 35 Times in 35 Posts
    Can you be more specific about where the spaces could possibly be? Are they always at the end of a string followed by a closing </p> tag?

  • #3
    New Coder
    Join Date
    Sep 2011
    Posts
    69
    Thanks
    6
    Thanked 0 Times in 0 Posts
    no, the string is not with specific data

  • #4
    Regular Coder bacterozoid's Avatar
    Join Date
    Jun 2002
    Location
    USA
    Posts
    490
    Thanks
    24
    Thanked 35 Times in 35 Posts
    Without having a general idea of what your strings will look like, it's hard to find a regular expression or algorithm to handle the issue.

    PHP has a function called trim() that removes spaces from the beginning and end of lines...maybe that helps. Do you have some real data you can post along with what they should look like after removing the spaces?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •