Jump to content

Recommended Posts

Currently I am working on an email script. I need to be able to use a foreach inside of the message. something like this:

$message = '<table width="0" border="0" cellspacing="2" cellpadding="2">
 <tr>
   <td>Registrant</td>
   <td>Event</td>
   <td>Date</td>
   <td>Time</td>
   <td>Participants</td>
   <td> </td>
 </tr>
 <tr>
   <td>'.$name.'</td>
   <td>'.$event.'</td>
   <td>'.$date.'</td>
   <td>'.$time.'</td>
   <td>'.foreach($_POST["participant"] AS $key => $val) {
$participant = $val;
echo $participant;
}.'</td>
   <td> </td>
 </tr>
</table>';

 

I know this isnot the proper way to do it, so I was wondering, what is the proper way to do this, or what is the best way to achieve this result? any help is greatly appreciated

Link to comment
https://forums.phpfreaks.com/topic/272785-foreach-inside-of-a-string/
Share on other sites

Thanks for the tip. Testing:

 

$string = 'The start of the string ';
foreach($a as $B)
{
$string .= $b . ' ';
}
$string .= 'the end of the string';

 

Edit: turns out the problem isn't the editor, it's the software. Even without the editor, $b becomes $B.

Edited by haku

foreach($a as $B)

 

Edit: That does indeed do it. Thanks. But what a pain in the butt - particularly since it doesn't even render it as a smiley!

 

It probably doesn't allow smilies inside code blocks. But it is weird that it still parses the syntax regardless.

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.