Page 1 of 1

Editable Area

Posted: Fri Sep 22, 2006 6:15 am
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?

Posted: Fri Sep 22, 2006 6:22 am
by n00b Saibot
try

Code: Select all

preg_split("#<!--BEGIN EDITABLE--!>(.*?)<!--END EDITABLE--!>#is", $test);

Posted: Fri Sep 22, 2006 8:35 am
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?

Posted: Fri Sep 22, 2006 11:38 am
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.