string

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
zolo44
Forum Newbie
Posts: 21
Joined: Tue Jul 30, 2002 11:07 am

string

Post by zolo44 »

I'm having trouble with this problem. Hopefully somebody can help me.

Problem:

Using php, I need to create an array with all the matches of the strings starting with the word "INSERT" and end with the ";".

Now, since im new to all this, i thinking I need to use the preg_split() right? Or is something better then this?


Tried using something like this but is not working... probably don't have the right understanding of how it works yet.

Code: Select all

/CREATE.*;$/
Any help will be appreciated.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

try

Code: Select all

preg_match_all('#(?:^|;)\s*insert\s*(.*?)(?:;|$)#i',$data,$matches);
print_r($matches);
Last edited by feyd on Sat Aug 06, 2005 10:39 pm, edited 1 time in total.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Re: string

Post by anjanesh »

zolo44 wrote: an array with all the matches of the strings starting with the word "INSERT" and end with the ";".

Code: Select all

preg_match_all("/INSERT.*?;/is", $sqlContents, $matches)
print_r($matches);
zolo44
Forum Newbie
Posts: 21
Joined: Tue Jul 30, 2002 11:07 am

Post by zolo44 »

thanks guys, they both worked.
Post Reply