Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2002
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help with a regex

    I need some help with a regex. I need it to pull the data from a specific content in a language file which details info about the language file.

    The comment looks like this:

    Code:
    /************************************************
    LANGUAGE FILE
    SITE: MySite
    LANGUAGE: English
    FILE: en.php
    ************************************************/
    I need to get the information so that I can easily figure out that SITE = MySite, LANGAUGE = English, and so on. So I would either need an array like this:

    array(

    array('SITE','MySite'),
    array('LANGAUGE','English),
    etc.
    );

    or something like this:

    array('SITE: MySite', 'LANGUAGE: English', etc.);

    Right now I have a regex which does not work at all - it returns just an empty array when used in conjunction with preg_match_all(). The regex I have come up with so far is:

    PHP Code:
    $pattern="/^(\/[\*]*)(^LANGUAGE\sFILE)(^.*)*(^[\*]*\/*)/smU"
    Thanks in advance for any help in fixing this regex or in pointing me in the right direction.

  • #2
    New Coder
    Join Date
    Sep 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't know exactly where your getting the string, but if it's from a file, you could do something like...

    // there is no checking (file exists, is readable), as it's just example

    PHP Code:
    <?php

    function get_comment_array $file$data ''$find '/' )
    {
        
    $io fopen $file'rb' );

        do
        {
            
    $data .= fgets $io4096 );

        } while ( 
    substr_count $data$find ) != && ! feof $io ) );

        
    fclose $io );

        
    preg_match_all '/(\w+)\s?\:\s?([a-z0-9\.]+)\r?\n/is'$data$m );

        return 
    array_combine $m[1], $m[2] );
    }

    $file './some_file.php';

    $array get_comment_array $file );

    print_r $array );

    ?>


  •  

    Posting Permissions

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