From: 7stud -- Date: 2009-07-20T09:17:07+09:00 Subject: Re: Hpricot - strip out images and show first x words Max Williams wrote: > Hi 7stud, thanks. > > This seems to return the first 25 words of every paragraph? Well, what does this say: > I have a bunch of html in p tags and i want to show shorted > summary - like the first 25 words followed by '...'. If you want relevant answers, then you have to post precise questions. So now you just want **the first 25 words of your html**? html =<From the UKTI blog:

\n

Early on 20 January 2009, nine British new media innovators and I arrived at the Foreign Office for a meeting with the Foreign Secretary, David Milliband MP, to discuss how government can support this important sector. ENDOFHTML max_words = 25 no_images = html.gsub(/<\s*img.*?>/, "") words = no_images.split() if words.length <= 25: puts words.join(" ") else puts "#{words[0, 25].join(" ")}..." end --output:--

From the UKTI blog:

Early on 20 January 2009, nine British new media innovators and I arrived at the Foreign Office for a... -- Posted via http://www.ruby-forum.com/.