...

View Full Version : Remove Whitespace before and after comma



conware
09-10-2011, 12:30 PM
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?



this, is, a , test , string ,

Could I change the above string into this:


this, is, a, test, string,

with preg_replace?

My current preg_replace looks like this:



<?php
$string = 'this, is, a , test , string , ';
$string = preg_replace('/[^a-zA-Z0-9\s,]/', '', $string);
?>


Thanks for any help.

sunfighter
09-10-2011, 02:52 PM
Simpler:

$my = str_replace(' , ', ', ', "this, is, a , test , string ,");
echo $my;

conware
09-10-2011, 05:35 PM
Thanks for the reply sunfighter :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum