string processing question

This is a discussion on string processing question within the PHP Language forums, part of the PHP Programming Forums category; Given a string: 'aaa bbbb cccc' or a string: 'aaaa bbb cc' I want to find and delete any word ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-17-2005
leegold
 
Posts: n/a
Default string processing question

Given a string: 'aaa bbbb cccc'
or a string: 'aaaa bbb cc'

I want to find and delete any word within a string with 3 or less chars.
so I would get:
'bbbb cccc'
'aaaa'
as results after processing.

How would I do this in PHP?

Thanks
Reply With Quote
  #2 (permalink)  
Old 02-17-2005
Chung Leong
 
Posts: n/a
Default Re: string processing question

"leegold" <leegold@nospam.com> wrote in message
news:D8OdnStQkasrgInfRVn-jg@rcn.net...
> Given a string: 'aaa bbbb cccc'
> or a string: 'aaaa bbb cc'
>
> I want to find and delete any word within a string with 3 or less chars.
> so I would get:
> 'bbbb cccc'
> 'aaaa'
> as results after processing.
>
> How would I do this in PHP?
>
> Thanks


preg_replace('/\b\S{1,3}\b\s*/', '', $text) should do it.


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:30 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0