SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jul 2003
    Location
    USA
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Need help converting to an array...

    Thanks in advance to any one that offers the least of help.
    -------------

    Let's say I have a template file that holds this DATA:
    PHP Code:
    SITE CONTENT GOES HERE
    <!-- BEGIN BLOCK -->
         
    I am in BLOCK
         
    <!-- BEGIN BLOCKA -->
             
    I am in BLOCKA
         
    <!-- END BLOCKA -->
         
    I AM ALSO IN BLOCK
         
    <!-- BEGIN BLOCKB -->
             
    I AM IN BLOCKB
             
    <!-- BEGIN BLOCKC -->
                 
    I AM IN BLOCKC 
             
    <!-- END BLOCKC -->
         <!-- 
    END BLOCKB-->
    <!-- 
    END BLOCK --> 
    how would I be able to parse that text to yield an array consisting of properly nested tokens(blocks)?
    ie. given the information above I should wind up with an array similar to this one:
    PHP Code:
    [TEMPLATE] => array(
        [
    0] => SITE CONTENT GOES HERE
        
    [BLOCK] => array(
            [
    0] => I AM IN BLOCK
            
    [BLOCKA] => array(
                [
    0] => I AM IN BLOCKA
             
    )
            [
    BLOCKB] => array(
                [
    0] => I AM IN BLOCKB
                
    [BLOCKC] => array(
                    [
    0] => I AM IN BLOCKC
                
    )
            )
        )


  2. #2
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ouch... All I can think of is dynamically created multi-dimensional arrays and it gives me a head-ache. Are you sure you want to pursue this method?
    John

  3. #3
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    All I can suggest (because I don't really want to try tackling this either ) is take a look at the manual. Here are some functions that'll help with this

    strpos()
    substr()

    Another option, go download phpBB and have a look at some code in the file /includes/template.php. It has some templating functions that might give you some ideas for code. Specifically the *_block_* functions.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •