Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Senior Member jf1288's Avatar
    Join Date
    Sep 2003
    Posts
    215
    Member #
    3300
    I'm trying to have a conditional feature in my template system.

    The source consists of something like:

    HTML Code:
    Some before HTML
    
    <!-- begin:NOT_LOGGED_IN -->
    
    This content shown only when $SWITCHES['NOT_LOGGED_IN'] is true
    
    <!-- end:NOT_LOGGED_IN -->
    <!-- begin:LOGGED_IN -->
    
    This content shown only when $SWITCHES['LOGGED_IN'] is true
    
    <!-- end:LOGGED_IN -->
    The php that I have that processes this is:

    PHP Code:

      
    foreach($SWITCHES as $key => $show) {
        if(
    $show) {
            
    preg_replace("\<!-- begin:$key -->(.*?)\<!-- end:$key -->","$1",$skin);
        }
      }
      
      
    preg_replace("\<\!-- begin:[A-Z]+ --\>(.+?)\<\!-- end:[A-Z]+ --\>","",$skin); 
    When I run it (See it here) I get the errors:
    Code:
    Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in /home/ab/public_html/sources/template.php on line 32
    Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in /home/ab/public_html/sources/template.php on line 36
    Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in /home/ab/public_html/sources/template.php on line 32
    Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in /home/ab/public_html/sources/template.php on line 36
    (To see the errors on tha pages I link to you will need to highlight everything)

    What I want to do is compute during the course of the script which sections I want to show and then set $SWITCH['SECTION_NAME'] = 1.
    When it processes it will go through and remove the conditional tags around the code for anything that has been set to 1 (Marked as 'I want to show this block'). The second preg_replace will remove anything other conditional blocks(Including the comment tags) that has not been set to 1.

    What are the patters that I should use to do this? A live example is here where you can see that it is not removing any of the blocks, whether I want them or not, and is throwing out errors.
    If its not in Family Guy its not worth it.

  2.  

  3. #2
    Senior Member
    Join Date
    Aug 2003
    Posts
    444
    Member #
    2801
    Just read the error and tells you exactly what's wrong: Your regex delimiter is a backslash, and that won't work (as per the error message). Try another delimieter, perhaps like... (see below).

    Also, you need to escape the single dashes as they are part of the regex syntax, so:

    PHP Code:

    foreach($SWITCHES as $key => $show) {
        if(
    $show) {
            
    preg_replace("/<!\-\- begin:$key -->(.*?)\<!\-\- end:$key \-\->/","$1",$skin);
        }
      }
      
      
    preg_replace("/<\!\-\- begin:[A-Z]+ \-\-\>(.+?)\<\!\-\- end:[A-Z]+ \-\-\>/","",$skin); 
    Hope this helps...
    eKstreme
    eKstreme.com - Free website tools!
    fontfox - free fonts Hand-picked quality fonts.

  4. #3
    Senior Member jf1288's Avatar
    Join Date
    Sep 2003
    Posts
    215
    Member #
    3300
    no errors, but it doesn't do anything. It doesn't replace anything.
    If its not in Family Guy its not worth it.

  5. #4
    Senior Member jf1288's Avatar
    Join Date
    Sep 2003
    Posts
    215
    Member #
    3300
    Ok, I got it:
    PHP Code:
      foreach($SWITCHES as $key => $show) { 
        if(
    $show) {
            
    $skin preg_replace("/<!-- begin:$key -->(.+)<!-- end:$key -->/s","$1",$skin); 
        } 
      } 
       
      
    $skin preg_replace("/<!-- begin:([A-Z|_]+) -->(.+)<!-- end:\\1 -->/s","",$skin); 
    Now depending on which values of SWITCHES are set, you get the correct section.
    If its not in Family Guy its not worth it.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:54 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com