Jump to content

Recommended Posts

I am by no means an expert at this, but the following does not work:

 

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

 

It is part of a larger script, however the script stops working directly at the end of "$a =>".

It instead decides to print the rest of the script ($b and onwards) in the browser window.  Is there anything else I need to be aware of or do you need me to post the entire script?

Link to comment
https://forums.phpfreaks.com/topic/141813-quick-question/
Share on other sites

That is the correct syntax...

$body = "We have received the following information:\n\n"; 
foreach($fields as $a => $b)
{ 
$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);
}

 

The only thing I can think of, would be to put single quotes around $a in the $_REQUEST... but the script shouldnt print itself (you are saying it's printing the code, correct?)

Link to comment
https://forums.phpfreaks.com/topic/141813-quick-question/#findComment-742464
Share on other sites

Okay, if you take out that loop - does it do anything odd?

 

Like this:

<?php
$body = "We have received the following information:\n\n"; 
/*foreach($fields as $a => $b)
{ 
$body .= sprintf("%20s: %s\n",$b,$_REQUEST['$a']);
}*/
?>

 

And that works okay?

 

if so, can you print_f($fields)?

Link to comment
https://forums.phpfreaks.com/topic/141813-quick-question/#findComment-742480
Share on other sites

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.