lewashby Posted January 2, 2016 Share Posted January 2, 2016 <?php require_once('init.php'); function print_rows($inmates) { foreach($inmates as $inmate) { echo "<tr>"; echo "<td><span class='rightpadding'>$inmate->get_property('first_name');</span>$inmate->get_property('number');<span class='rightpadding'>(W)</span>Facility<br /><br /><span class='dates'>8-05-15 <span class='red'>/</span> 8-08-15</span><a href=''><span class='edit'>Edit</span></a></td>"; echo "</tr>"; } } ?> In the code above my inmate object method calls are being displayed a literal strings in the output. How can I get these to expand in this string? I also tried concatenation with the . operator but the page wouldn't load at all using that method. Quote Link to comment https://forums.phpfreaks.com/topic/300097-echoing-strings-object-calls/ Share on other sites More sharing options...
Solution mac_gyver Posted January 2, 2016 Solution Share Posted January 2, 2016 (edited) your concatenation probably didn't work due to the semi-colons ;. those only go on the end of php statements. when not within a quoted string, the first semi-colon that was encountered was telling php that was the end of the statement. everything following that probably didn't make any sense to php and it was throwing a syntax error. to put the object method calls in the string, you would need to put { } around each object method call so that php can figure out what part is the reference to the object. you would also remove the semi-colons, unless you literally want the ; character to be in the output. Edited January 2, 2016 by mac_gyver 1 Quote Link to comment https://forums.phpfreaks.com/topic/300097-echoing-strings-object-calls/#findComment-1528970 Share on other sites More sharing options...
lewashby Posted January 2, 2016 Author Share Posted January 2, 2016 Thanks mac_gyver, that got it. Quote Link to comment https://forums.phpfreaks.com/topic/300097-echoing-strings-object-calls/#findComment-1528989 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.