perl to php translation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • alexjaquet@gmail.com

    perl to php translation

    Hi,

    I'm new to php and I'm trying to translate the following code :

    sub loadPreferences Auto {
    local our $content;
    open (FILE, "<$dir/preferences_aut o.html") or die "cannot open file
    $dir/preferences_aut o.html";
    while (<FILE>) {
    s/\$LABEL{'([\w]+)'}/ exists $SERVER{$1} ? $SERVER{$1} : $1 /eg;
    s/\$LANG/$lang/g;
    s/\$ERROR{'([\w]+)'}//g;
    s/\$SESSIONID/$session_id/g;
    $content .= $_;
    }
    $content = Compress::Zlib: :memGzip($conte nt) if $can_do_gzip; ;
    print "Content-Length: ", length($content ) , "\n";
    print "Content-Encoding: gzip\n" ;
    print "Content-Type: text/html\n\n";
    print $content;
    close (FILE);
    }

  • milahu

    #2
    Re: perl to php translation

    Hope this works...

    <?php
    function loadPreferences Auto()
    {
    // init gzip buffer
    ob_start('ob_gz handler');
    // read file
    $content = file_get_conten ts($dir.'prefer ences_auto.html ');
    // do replacements
    $content = preg_replace_ca llback(
    '/$LABEL\{\'(\w+) \'\}/', // ?
    create_function (
    '$matches',
    'return isset($_SERVER[$matches[0]]) ? $_SERVER[$matches[0]] :
    $matches[0];'
    ),
    $content
    );
    $content = str_replace('$L ANG', $lang, $content);
    $content = preg_replace('$ ERROR\{\'(\w+)\ '\}', '', $content);
    $content = str_replace('$S ESSIONID', $session_id, $content);
    }
    ?>

    Comment

    Working...