xyn Posted September 25, 2008 Share Posted September 25, 2008 First off, I would like to apologise for posting this, in the "incorrect" area, as i couldn't find the specific regex board. Secondly, I've been working on my own basic template engine, every thing has been working fine, up until i used multiple IF STATEMENTS within my html template page: The Template file: [code=php:0]<table width="600" cellspacing="0" cellpadding="0"> <tbody> {0|if:rows=0} <!-- No items in basket --> <tr class="formbg"> <td colspan="2" width="600" height="25" class="head2" style="padding-left:5px;"> There are not any products in your shopping basket! </td> </tr> {0|else} {while} {1|if:row=1} <!-- The headings for the basket table --> <tr class="formbg"> <td width="300" height="25" class="head3" style="padding-left:5px;"> Heading </td> <td width="300" height="25" class="head3"> Title </td> </tr> {1|endif} <!-- The basket items --> <tr class="formbg"> <td width="300" height="25" class="head3" style="padding-left:5px;"> - </td> <td width="300" height="25" class="head3"> - </td> </tr> {endwhile} {0|endif} </tbody> </table> [/code] Basically I can collect the table row between {0|if:rows=0} and {0|else}. I can also collect everything from {while} to {endwhile} between {0|else} and {0|endif}. However, when i try to extract the following as separate items, the regular expressions will not work... [code=php:0]{1|if:row=1} <!-- The headings for the basket table --> <tr class="formbg"> <td width="300" height="25" class="head3" style="padding-left:5px;"> Heading </td> <td width="300" height="25" class="head3"> Title </td> </tr> {1|endif} [/code] My php code: [code=php:0]function basket_checkout(){ # define smart tags $smart_tags=array( array() ); # select products in basket $cart=mysql_query("select * from `sc_cart_basket` where `sc_basket_user`='{$_SESSION[$this->c_session]}' order by `sc_basket_added` asc"); $cart_html=file_get_contents("$this->c_root/basket_checkout.inc.php"); # regular expressions $pattern_elseif_1="/^(.*?)\{(0\|if:rows=0)\}(.*?)\{(0\|else)\}(.*?)\{(0\|endif)\}(.*?)$/us"; $pattern_while="/^(.*?)\{(while)\}\{(1\|if:row=1)\}(.*?)\{(1\|endif)\}(.*?)\{(endwhile)\}(.*?)$/us"; $html_table_start=preg_replace($pattern_elseif_1, "\\1", $cart_html); # start table $html_no_rows=preg_replace($pattern_elseif_1, "\\3", $cart_html); # if no mysql rows, insert 1 table row $html_basket_while=preg_replace($pattern_elseif_1, "\\5", $cart_html); # the while loop $html_basket_itmes=preg_replace($pattern_while, "\\4", $html_basket_while); # DEBUG 1 $html_table_end=preg_replace($pattern_elseif_1, "\\7", $cart_html); # end the table (debug only) echo $html_table_start, $html_basket_itmes, $html_table_end; // --> } [/code] Link to comment https://forums.phpfreaks.com/topic/125803-solved-regex-issues/ Share on other sites More sharing options...
xyn Posted September 25, 2008 Author Share Posted September 25, 2008 I fixed it.. the regex i now use is... "/^(.*?)\{(while)\}(.*?)\{(1\|if:row=1)\}(.*?)\{(1\|endif)\}(.*?)\{(endwhile)\}(.*?)$/us"; Link to comment https://forums.phpfreaks.com/topic/125803-solved-regex-issues/#findComment-650515 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.