searls03 Posted January 7, 2013 Share Posted January 7, 2013 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 More sharing options...
requinix Posted January 7, 2013 Share Posted January 7, 2013 Construct the string in three parts: $message = everything up until the foreach, then $message .= stuff inside the loop, then finally $message .= the stuff after the foreach. Link to comment https://forums.phpfreaks.com/topic/272785-foreach-inside-of-a-string/#findComment-1403823 Share on other sites More sharing options...
searls03 Posted January 7, 2013 Author Share Posted January 7, 2013 how do I do the foreach part though? do I do it inside the quotes? or does it happen outside the quotes....I need the loop to display inside of one cell. Link to comment https://forums.phpfreaks.com/topic/272785-foreach-inside-of-a-string/#findComment-1403824 Share on other sites More sharing options...
haku Posted January 7, 2013 Share Posted January 7, 2013 $string = 'The start of the string '; foreach($a as $B) { $string .= $b . ' '; } $string .= 'the end of the string'; Edit: This stupid editor keeps changing $b to $B. Pretend that the $B is a $b. Link to comment https://forums.phpfreaks.com/topic/272785-foreach-inside-of-a-string/#findComment-1403826 Share on other sites More sharing options...
scootstah Posted January 7, 2013 Share Posted January 7, 2013 Edit: This stupid editor keeps changing $b to $B. Pretend that the $B is a $b. Click the little button in the very top left of the reply box and the "stupid editor" will turn off. Link to comment https://forums.phpfreaks.com/topic/272785-foreach-inside-of-a-string/#findComment-1403845 Share on other sites More sharing options...
haku Posted January 7, 2013 Share Posted January 7, 2013 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. Link to comment https://forums.phpfreaks.com/topic/272785-foreach-inside-of-a-string/#findComment-1403851 Share on other sites More sharing options...
scootstah Posted January 7, 2013 Share Posted January 7, 2013 foreach($a as $B) EDIT: Well, that's a stupid bug. Link to comment https://forums.phpfreaks.com/topic/272785-foreach-inside-of-a-string/#findComment-1403852 Share on other sites More sharing options...
requinix Posted January 7, 2013 Share Posted January 7, 2013 foreach($a as $b) [edit] It's the smiley. Hit the "disable emoticons" option in the full editor. Link to comment https://forums.phpfreaks.com/topic/272785-foreach-inside-of-a-string/#findComment-1403860 Share on other sites More sharing options...
haku Posted January 7, 2013 Share Posted January 7, 2013 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! Link to comment https://forums.phpfreaks.com/topic/272785-foreach-inside-of-a-string/#findComment-1403862 Share on other sites More sharing options...
scootstah Posted January 7, 2013 Share Posted January 7, 2013 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. Link to comment https://forums.phpfreaks.com/topic/272785-foreach-inside-of-a-string/#findComment-1403864 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.