Any questions involving matching text strings to patterns - the pattern is called a "regular expression."
Moderator: General Moderators
andym01480
Forum Contributor
Posts: 390 Joined: Wed Apr 19, 2006 5:01 pm
Post
by andym01480 » Fri Sep 22, 2006 6:15 am
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?
n00b Saibot
DevNet Resident
Posts: 1452 Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:
Post
by n00b Saibot » Fri Sep 22, 2006 6:22 am
try
Code: Select all
preg_split("#<!--BEGIN EDITABLE--!>(.*?)<!--END EDITABLE--!>#is", $test);
andym01480
Forum Contributor
Posts: 390 Joined: Wed Apr 19, 2006 5:01 pm
Post
by andym01480 » Fri Sep 22, 2006 8:35 am
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?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Sep 22, 2006 11:38 am
"#" is being used as a starting/ending delimiter. The "is" following the latter delimiter is a mode setting: case
i nsensitive, single
s tring 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.