Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP RegEx Remove Space After Every Comma In String
    primarykey
    data
    text
    <p>Hey all. I have a string of names separated by commas. I'm exploding this string of names into an array of names with the comma as the delimiter. I need a RegEx to remove a white space(if any) only after the comma and not the white space between the first and last name.</p> <p>So as an example:</p> <pre><code>$nameStr = "Sponge Bob,Bart Simpson, Ralph Kramden,Uncle Scrooge,Mickey Mouse"; </code></pre> <p><strong>See the space before Ralph Kramden?</strong> I need to have that space removed and not the space between the names. And I need to have any other spaces before names that would occur removed as well.</p> <p><strong>P.S.:</strong> I've noticed an interesting behavior regarding white space and this situation. Take the following example:</p> <p><strong>When not line breaking an echo like so:</strong></p> <pre><code>$nameStr = "Sponge Bob,Bart Simpson, Ralph Kramden,Uncle Scrooge,Mickey Mouse"; $nameArray = explode(",", $nameStr); foreach($nameArray as $value) { echo $value; } </code></pre> <p><strong>The result is:</strong> Sponge BobBart Simpson Ralph KramdenUncle ScroogeMickey Mouse </p> <p><strong>Notice the white space still there before Ralph Kramden</strong></p> <p>However, when line breaking the above echo like so:</p> <pre><code>echo $value . "&lt;br /&gt;"; </code></pre> <p>The output is:</p> <p>Sponge Bob</p> <p>Bart Simpson</p> <p>Ralph Kramden</p> <p>Uncle Scrooge</p> <p>Mickey Mouse</p> <p><strong>And all of the names line up with what appears to be no white space before the name.</strong></p> <p><strong>So what exactly is PHP's behavior regarding a white space at the start of a string?</strong></p> <p>Cheers all. Thanks for replies.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload