PDA

View Full Version : Help with regexps


Thejavaman1
10-05-2002, 11:05 PM
I have never liked them, but I need to use them. Basicly this is what I want to do.

Take this


<html>
<head>
<title>%page_title%</title>
</head>
<body>
%page_header%
blah blah blah<br />
%page_content%
blah blah blah
%page_footer%
<body>
</html>


And turn that into an array like

items[0] = page_title
items[1] = page_header
items[2] = page_content
items[3] = page_footer

I think this can be done with regexp, however I don't know how to do it... :(

mordred
10-06-2002, 03:56 PM
I suspect that you want to match all characters within those percent signs and have those matches in an array. If otherwise, please elaborate, but you could try this as a starting point:


preg_match_all('/%(.+?)%/', $x, $matches);
$items = $matches[1];

Thejavaman1
10-16-2002, 06:47 AM
hey, thanks. sorry about not posting eariler, but I have been busy... :(

It seems that $items[1] stores an array of the values with out the %'s where $items[0] stores the values with them...