Jump to content

Help Needed Porting this PERL routine to PHP


calane

Recommended Posts

After a full day of attemping to port this PERL routine to PHP, I have given up on being able to do this myself, can anybody help?


[code] for($y=1;$y<=100;$y++){
$thename="NAME_$y";
if(length(${$thename})>3){
$num++;
}
}
foreach($x=1; $x<=$num; $x++){
$qnt="QUANTITY_$x";
$prce="PRICE_$x";
$xtnd="XTEND_$x";
$ide="ID_$x";
$naam="NAME_$x";
$adlinfo="ADDTLINFO_$x";
${$naam}=~ s/\n//g;
$strMessageBody .= "Qty: ${$qnt}  \nItem No: ${$ide}  \nDescpition: ${$naam}  \nAddtl. Info: ${$adlinfo}  \nPrice: \$${$prce}      Extended Price: \$${$xtnd} \n\n";
}[/code]
My perl's a bit rusty.. is length() length of a string?  I replaced it with strlen().  As for the ${$var} construct, you can do that as $$var in php.  That means "The value of the variable named by the contents of $var".

The regexp was simple so I used str_replace().  But in general you can use preg_replace() to do a perl style regexp replacement, and preg_match() to do a perl style regexp match.

[code=php:0] for($y=1;$y<=100;$y++){
$thename="NAME_$y";
if(strlen($$thename)>3){
$num++;
}
}
for($x=1; $x<=$num; $x++){
$qnt="QUANTITY_$x";
$prce="PRICE_$x";
$xtnd="XTEND_$x";
$ide="ID_$x";
$naam="NAME_$x";
$adlinfo="ADDTLINFO_$x";
$$naam = str_replace("\n", '', $$naam);
$strMessageBody .= "Qty: {$$qnt}  \nItem No: {$$ide}  \nDescpition: {$$naam}  \nAddtl. Info: {$$adlinfo}  \nPrice: \${$$prce}      Extended Price: \${$$xtnd} \n\n";
}[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.