Solved

Simple regular expressions question

Posted on 2007-04-07
2
197 Views
Last Modified: 2013-12-12
Hello,

starting from a good base knowledge of regular expressions, I would like to know how to use them in Php.
Basically, I have a very simple SQL query structured like this:

SELECT field1, field2, ... , fieldN FROM tableX WHERE [conditions]

I would like to take this string and put the various select fields in an array of size (N - 1) which in the end will contain the various (field1, field2, ... , fieldN).

If you just show me how to do, I think I will be able to extrapolate the mechanism from your answer.
Thanks in advance.
0
Comment
Question by:Emanuele_Ciriachi
2 Comments
 
LVL 27

Accepted Solution

by:
yodercm earned 250 total points
ID: 18869970
You might consider working with explode instead of regular expressions, it's much easier.  You'd only have to deal with spaces and commas separating your words.

Start by removing the commas with a regular expression or any other simple means, then use

$array = explode(" ",$string);

http://us.php.net/manual/en/function.explode.php
0
 
LVL 1

Author Comment

by:Emanuele_Ciriachi
ID: 18871966
Worked fine with explode(), thanks.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question