Editable Area

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

Moderator: General Moderators

Post Reply
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Editable Area

Post by andym01480 »

I want to be able to use preg_split to yank out the editable bit of a variable for a simple cms

Code: Select all

$test="blah blah rhubarb<!--BEGIN EDITABLE--!>Editable bit<!--END EDITABLE--!>blah blah rhubarb";
$editable=preg_split("<!--BEGIN EDITABLE--!>[A-za-z0-9]+<!--END EDITABLE--!>",$test);
print_r($editable);
is not working at all!

What regex would work please?
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

try

Code: Select all

preg_split("#<!--BEGIN EDITABLE--!>(.*?)<!--END EDITABLE--!>#is", $test);
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Post by andym01480 »

Thanks for that. That yanks the editable bit out which is what I asked for.
But I didn't frame the question very well!

1)How do I populate an array with the stuff before and after the editable tags? ( It's so I can show the non editable bits with a textarea for the editable bits)
2) What does # and #is do?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

"#" is being used as a starting/ending delimiter. The "is" following the latter delimiter is a mode setting: case insensitive, single string mode.

Code: Select all

$parts = preg_split('#(<!--(?:BEGIN|END) EDITABLE-->)#', $string, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
may be of interest or more useful.
Post Reply