Solved

Simple regular expressions question

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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.

911 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

16 Experts available now in Live!

Get 1:1 Help Now