Any questions involving matching text strings to patterns - the pattern is called a "regular expression."
Moderator: General Moderators
alex.barylski
DevNet Evangelist
Posts: 6267 Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg
Post
by alex.barylski » Tue Jan 16, 2007 3:10 pm
Code: Select all
$html = preg_replace("/<!-- START_NAV_MENU -->(.+)<!-- END_NAV_MENU -->/", $menu_html, $html);
1) Will this find a single occurance of the HTML comments and everything inbetween it?
2) When it replaces the comments stay put or do I have to wrap $menu_html with tags again?
Cheers
alex.barylski
DevNet Evangelist
Posts: 6267 Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg
Post
by alex.barylski » Tue Jan 16, 2007 3:18 pm
Yes...nothing happened...
Latest:
Code: Select all
$html = preg_replace("/\<\!\-\- START_NAV_MENU \-\-\>(.*)\<\!\-\- END_NAV_MENU \-\-\>/", $menu_html, $html);
This appears to be match other comments and reproducing/replicating those a few times???
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jan 16, 2007 3:34 pm
".*?"
"s" modifier too. No need for all the escaping, they aren't metacharacters.
alex.barylski
DevNet Evangelist
Posts: 6267 Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg
Post
by alex.barylski » Tue Jan 16, 2007 3:41 pm
feyd wrote: ".*?"
"s" modifier too. No need for all the escaping, they aren't metacharacters .
I didn't think so...but I had no other idea WTF was going on and figured they didn't hurt
but i'll remove them for sure thanks