Web Analytics Made Easy -
StatCounter Remove Whitespace before and after comma - CodingForum

Announcement

Collapse
No announcement yet.

Remove Whitespace before and after comma

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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; Sep 10, 2011, 07:35 AM.

  • #2
    Simpler:
    PHP Code:
    $my str_replace(' , '', '"this, is, a , test , string   ,");
    echo 
    $my
    Evolution - The non-random survival of random variants.
    Physics is actually atoms trying to understand themselves.

    Comment


    • #3
      Thanks for the reply sunfighter

      Comment

      Working...
      X
      😀
      🥰
      🤢
      😎
      😡
      👍
      👎