Jump to content

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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.