SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Removing space

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does anyone know how to remove white space in php (without removing the spaces which occur in text etc)???? To get a document that looks like this;

    <A href="#1">
    Lampard denies quit

    </A>

    to this???

    <A href="#1">Lampard denies quit talk</A>





    I've tried various different configurations simialr to this but can't get it to work:

    $printing[1] = ereg_replace([:space:], "", $printing[1]);


  2. #2
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've looked in the PHP Manual and it looks like I need to use either the chop or trim function. However, the manual being as explanitory as ever (not!!) does not show me how to use it. Could anyone show me how I could put the function in after this line:

    $printing[1] = str_replace($From[$i], "$To[$i]", $printing[1]);
    Trim or chop $printing[1] somehow?????????????


  3. #3
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I believe trim() is removing spaces both ends of a string
    while chop() will return a string with no space(including new lines).

    So probably you could use chop like this:
    Code:
    $returnStr = chop($inputStr);
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  4. #4
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried this and it didn't do anything - if I'm missing something stupid please point it out.

    $printing[1] = str_replace($From[$i], "$To[$i]", $printing[1]);
    $printing[1] = chop ($printing[1]);


  5. #5
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For those interested I got this to work:
    $printing[1] = eregi_replace("[[:space:]][[:space:]]", "", $printing[1]);

    ie two spaces together!!!

    It does put EVERYTHING on one line though!!


Bookmarks

Posting Permissions

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