473,395 Members | 1,368 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

select first fifteen words

tolkienarda
316 100+
hi all

i need to select the first fifteen words of an article stored in a mysql database. so i have the basic idea laid out but the exact syntax seems a bit confusing. i have a book here on regular expressions and i think it has confused more than before.

so here is basicaly what i want to do

select the first word what ever it may be, so /S+ i think should match 1 or more non white space charters and then a /s then repete that fifteen times like so

/S+/s/S+/s/S+/s/S+/s/S+/s/S+/s/S+/s/S+/s/S+/s/S+/s/S+/s/S+/s/S+/s/S+/s/S+/s

now i know that there has to be a better way to do that so if anyone knows please relive my ignorance

eric
Mar 19 '07 #1
5 1478
Motoma
3,237 Expert 2GB
Do you need to select fifteen words using SQL or are you doing it with PHP?
Mar 20 '07 #2
tolkienarda
316 100+
i am currently trying to do it in php but if there is a good way to do it with sql i would be open to doing it that way.

eric
Mar 20 '07 #3
Motoma
3,237 Expert 2GB
i am currently trying to do it in php but if there is a good way to do it with sql i would be open to doing it that way.

eric
In PHP just explode() on spaces, and do a for loop to concatenate the first 15 words.
Mar 20 '07 #4
tolkienarda
316 100+
wow that makes life easy

i thought i was going to have to use regular expressions. and i have been avoiding those and hope i can continue to do so for the remainder of time

eric
Mar 20 '07 #5
steven
143 100+
Uhhh, that's a longwinded way of doing it though.

It would be much simpler to use a regular expression.

Expand|Select|Wrap|Line Numbers
  1. $expression = "/(\w+\s+){15}/";
  2. $words = "this is a sentence containing a good deal more than fifteen different words but only the first 15 words should be matched!";
  3. preg_match($expression, $words, $matches);
  4.  
The output of $matches[0]

this is a sentence containing a good deal more than fifteen different words but only
Mar 21 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Jeff Sandler | last post by:
I need a MySQL select statement as part of a PHP script. I want to find rows where a certain column either starts with or equals a user-supplied string. The string will be 1 or more characters in...
1
by: Mariusz | last post by:
Hi does anyone know an easy way to define object <select> in that way when clicking on it works as right alt is used. In other words - I need to rebuild select than when I click on first option...
3
by: dumbledad | last post by:
Hi All, I'm confused by how to replace a SELECT statement in a SQL statement with a specific value. The table I'm working on is a list of words (a column called "word") with an index int...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
4
by: Ben | last post by:
I believe I am missunderstanding how subqueries work. I simple subquery works fine but when I wish do compare 2 or more fields at once I don't get the results I wish. Table A...
16
by: Brian D | last post by:
I have a multiple select list that is created dynamically based on a previous selection on an asp page. The first thing I do is to clear the curent option list by ...
2
by: John Bailo | last post by:
I can say SELECT "HELLO" and it returns HELLO But say I want to return a table
7
by: php_mysql_beginer911 | last post by:
Hi .. hope someone will help i am trying to figure it out why i cannot post string "union select" every time i try to post data which content union and select .. the page doesn't get posted and...
6
by: dbuchanan | last post by:
There are three parts to this 1.) How do I cascade menus? 2.) And, how do I cascade menus with a multi-select CheckBoxList?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.