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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Mar 2010
    Posts
    199
    Thanks
    78
    Thanked 5 Times in 5 Posts

    Remove Whitespace before and after comma

    Hi guys,

    I was wondering if its possible with preg_replace to remove whitespace before and after a comma and limit words in a string to have atleast 3 letters?

    Code:
    this, is, a , test , string   ,
    Could I change the above string into this:
    Code:
    this, is, a, test, string,
    with preg_replace?

    My current preg_replace looks like this:

    PHP Code:
    <?php
    $string 
    'this, is, a , test , string   , ';
    $string preg_replace('/[^a-zA-Z0-9\s,]/'''$string);
    ?>
    Thanks for any help.
    Last edited by conware; 09-10-2011 at 12:35 PM.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,026
    Thanks
    23
    Thanked 588 Times in 587 Posts
    Simpler:
    PHP Code:
    $my str_replace(' , '', '"this, is, a , test , string   ,");
    echo 
    $my

  • Users who have thanked sunfighter for this post:

    conware (09-10-2011)

  • #3
    Regular Coder
    Join Date
    Mar 2010
    Posts
    199
    Thanks
    78
    Thanked 5 Times in 5 Posts
    Thanks for the reply sunfighter


  •  

    Posting Permissions

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