Solved

Simple regular expressions question

Posted on 2007-04-07
2
194 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now