calane Posted December 16, 2006 Share Posted December 16, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/30898-help-needed-porting-this-perl-routine-to-php/ Share on other sites More sharing options...
btherl Posted December 19, 2006 Share Posted December 19, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/30898-help-needed-porting-this-perl-routine-to-php/#findComment-144305 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.