/    Sign up×
Community /Pin to ProfileBookmark

How do i echo php in html?

I want to echo out <?php echo “”.floor($diff/60/60/24/365.25). ” “; ?> instead of $row[‘age’] in the td. How do i do that?

[code=php]

echo “<tr id=’tr1′>”;
echo “<td id=’td2′>…</td>”;
echo “<td id=’tdm1′><p id=’p1′> <u><b> “. $row[‘age’] . “</td>”;
echo “</tr>”;
}
echo “</table>”;

[/code]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@jag1authorJun 27.2015 — I was thinking about saving the echo "".floor($diff/60/60/24/365.25) in a variable but you cant save "echo" in a variable, can you?
Copy linkTweet thisAlerts:
@NogDogJun 28.2015 — Is this what you mean?
[code=php]
echo "<tr id='tr1'>";
echo "<td id='td2'>...</td>";
echo "<td id='tdm1'><p id='p1'> <u><b> ". floor($diff/60/60/24/365.25) . "</td>";
echo "</tr>";
}
echo "</table>";
[/code]

Though it might be simpler to exit out of PHP mode until you really need it:
[code=php]
?>
<tr id='tr1'>
<td id='td2'>...</td>
<td id='tdm1'><p id='p1'> <u><b><?php echo floor($diff/60/60/24/365.25); ?></td>
</tr>
<?php } ?>
</table>
[/code]
Copy linkTweet thisAlerts:
@jag1authorJun 28.2015 — thats what i meant. it works, Thank you ?
Copy linkTweet thisAlerts:
@vlad360Jun 28.2015 — Think sprintf is more safe in some purposes, especially working with DB
[code=php]<?php
$num = 5;
$location = 'tree';

$format = 'There are %d monkeys in the %s';
echo sprintf($format, $num, $location);
?>
[/code]

more information on: http://php.net/manual/en/function.sprintf.php
×

Success!

Help @jag1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...