Results 1 to 1 of 1

Thread: preg_replace_callback question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    preg_replace_callback question

    I read this php code in site php.net

    my question How can I know deep level ?

    PHP Code:
    plain 
    [indent]  >> DEB LEVEL=1

    deep 
                   
    [indent] >> >> DEB LEVEL=2

                 deeper 

    [/indent]deep 

    [/indent]plain 



    PHP Code:
    <?php
    $input 
    "plain [indent] deep [indent] deeper[/indent]deep[/indent]plain";

    function 
    parseTagsRecursive($input)
    {

        
    $regex '#\[indent]((?:[^[]|\[(?!/?indent])|(?R))+)\[/indent]#';

        if (
    is_array($input)) {
            
    $input '<div style="margin-left: 10px">'.$input[1].'</div>';
        }

        return 
    preg_replace_callback($regex'parseTagsRecursive'$input);
    }

    $output parseTagsRecursive($input);

    echo 
    $output;
    ?>
    Last edited by prokhaled; Mar 18th, 2008 at 06:29 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width