Dooley28 Posted April 3, 2008 Share Posted April 3, 2008 Hey all, Was just wondering if anyone had a simple regex to rip all grammar out of a sentence or where I could get one? Thanks! Quote Link to comment Share on other sites More sharing options...
Caesar Posted April 3, 2008 Share Posted April 3, 2008 Bad grammer? Or grammar in general? <?php //Strip out anything that's not a number. $nustr = preg_replace('/[^0-9]/','',$str); ?> Quote Link to comment Share on other sites More sharing options...
Dooley28 Posted April 3, 2008 Author Share Posted April 3, 2008 Oh any grammar to be honest. So "Here is, some text!! Sir...." would go to an array something like this. array[0]=Here array[1]=is array[2]=some array[3]=text array[4]=Sir That would be great. Cheers Quote Link to comment Share on other sites More sharing options...
discomatt Posted April 3, 2008 Share Posted April 3, 2008 I believe \p{P} in regex matches punctuation Quote Link to comment Share on other sites More sharing options...
Caesar Posted April 3, 2008 Share Posted April 3, 2008 Oh...you want to put every word into an array? <?php $str = "This is a sentence that I'm using to test"; preg_match_all('/[aA-zZ\'\.]+/', $str,$words); ?> Above returns.... Array ( [0] => Array ( [0] => This [1] => is [2] => a [3] => sentence [4] => that [5] => I'm [6] => using [7] => to [8] => test ) ) Quote Link to comment Share on other sites More sharing options...
Dooley28 Posted April 4, 2008 Author Share Posted April 4, 2008 Cool that's perfect. Thank you sir! Quote Link to comment Share on other sites More sharing options...
writer Posted April 4, 2008 Share Posted April 4, 2008 <?php $str = "This is a sentence that I'm using to test"; preg_match_all('/[aA-zZ\'\.]+/', $str,$words); ?> Thanks for this. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.