Page 1 of 1

content between editable regions

Posted: Fri Sep 09, 2005 7:32 am
by Skittlewidth
I was using a regex to capture all the content of a page between the title tags and the body tags
which was:

Code: Select all

preg_match("/<title>(.*?)<\/title>.*?<body>(.*?)<\/body>/mis",$filetext, $matches);
But then I needed to start being a bit more selective so I added editable regions to the template file but I'm having a bit of trouble with the modified regex:

Code: Select all

preg_match("/<!-- TemplateBeginEditable name=\"title\" -->(.*?)<!-- TemplateEndEditable -->.*?<!-- TemplateBeginEditable name=\"content\" -->(.*?)<!-- TemplateEndEditable -->/mis",$filetext, $matches);
As you can see there are two regions I need to snatch the content from, but at the moment it doesn't get anything. Is it because there are spaces within the template tags? Or should I use more metacharacters and not try to be so literal? :?:

Posted: Fri Sep 09, 2005 8:35 am
by anjanesh
What happens with this ?

Code: Select all

preg_match("/<.*?TemplateBeginEditable name=\"title\".*?>(.*?)<.*?TemplateEndEditable.*?>.*?<.*?TemplateBeginEditable name=\"content\".*?>(.*?)<.*?TemplateEndEditable.*?>/mis", $filetext, $matches);

Posted: Fri Sep 09, 2005 8:42 am
by Skittlewidth
I think I tried something along those lines, but I just got this to work anyway:

Code: Select all

preg_match("/<\W{3} InstanceBeginEditable name=\"title\" \W{3}(.*?)<\W{3} InstanceEndEditable \W{2}>.*?\<\W{3} InstanceBeginEditable name=\"content\" \W{2}>(.*?)<\W{3} InstanceEndEditable \W{2}>/mis", $filetext, $matches)
Thanks for the suggestion though 8)

[edit] I've just realised that I had problems to start with because the editable regions in a template are marked up differently to the way they are marked out in a file created from the template i.e one is a "TemplateBeginEditable" and the other is " Instance BeginEditable" duh no wonder I had problems....[/edit] :oops: [/i]