473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

perl to php translation

Hi,

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

sub loadPreferencesAuto {
local our $content;
open (FILE, "<$dir/preferences_auto.html") or die "cannot open file
$dir/preferences_auto.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($content) 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);
}

Apr 17 '06 #1
1 1265
Hope this works...

<?php
function loadPreferencesAuto()
{
// init gzip buffer
ob_start('ob_gzhandler');
// read file
$content = file_get_contents($dir.'preferences_auto.html');
// do replacements
$content = preg_replace_callback(
'/$LABEL\{\'(\w+)\'\}/', // ?
create_function(
'$matches',
'return isset($_SERVER[$matches[0]]) ? $_SERVER[$matches[0]] :
$matches[0];'
),
$content
);
$content = str_replace('$LANG', $lang, $content);
$content = preg_replace('$ERROR\{\'(\w+)\'\}', '', $content);
$content = str_replace('$SESSIONID', $session_id, $content);
}
?>

Apr 18 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Wildpeaks | last post by:
My brain must be running slow because of New Year, but I'm missing the trick to define fields for a package. In php, I'd do: ---- <?php class MyObj{ var $param1; function...
16
by: squash | last post by:
a dumb question i had on my mind: Say you have a dynamically created web page . Isn't it more secure to write it in php since a visitor will not be able to tell it is dynamically created? But...
3
by: Helmut Jarausch | last post by:
Hi, having been a Perl fan for years I have nearly converted to Python. Still, there are LOTS and very good modules written in Perl. Is there a tool to lesson the burdon of translation of Perl...
42
by: Fred Ma | last post by:
Hello, This is not a troll posting, and I've refrained from asking because I've seen similar threads get all nitter-nattery. But I really want to make a decision on how best to invest my time....
6
by: Stephen Ferg | last post by:
I need to translate some Perl scripts into Python. When I went looking for a tool that would help automate the translation, I was rather surprised that I couldn't find anything. BridgeKeeper,...
41
by: Xah Lee | last post by:
here's another interesting algorithmic exercise, again from part of a larger program in the previous series. Here's the original Perl documentation: =pod merge($pairings) takes a list of...
1
by: Darshan | last post by:
I have n number of C files which have French + English comments in them. Now i have written a code which greps all the comments. What is the best way to get the comments translated using a online...
3
by: Jeremy Chapman | last post by:
I've got a 2rd party API written in perl. We want to use it by converting to a c# .net assembly. Essentially it does HTTP posts to a web page to send/receive data. I've never done perl, and am...
4
by: =?ISO-8859-7?B?1/H189zt6Ocgwfrt4eve?= | last post by:
How can I convert a perl script to Python? Thank you!
10
by: mm | last post by:
Is there a Perl to Python converter? Or in general: a XY to Python converter? Is see, that Python is much better then Perl anyway. But for beginners, they whant to konw how is this done with...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.