Answer the question
In order to leave comments, you need to log in
How to write php code in php variable?
<?php $html = ' '; ?> can I write php code there? I can't. Can
this code be written to the $html variable?
<div class="news-box2">
<img class="news-img" src="<?= $new->img ?>" alt="">
<div class="news-title-g"><?= StringHelper::truncate($new->title,25,'...'); ?></div>
</div>
Answer the question
In order to leave comments, you need to log in
Using concatenation:
$var = '<div class="news-box2">
<img class="news-img" src="' . $new->img . '" alt="">
<div class="news-title-g">' . StringHelper::truncate($new->title,25,'...') . '</div>
</div>';
$var = <<<EOL
<div class="news-box2">
<img class="news-img" src="{$new->img}" alt="">
<div class="news-title-g">{StringHelper::truncate($new->title,25,'...')}</div>
</div>
EOL;
ob_start(); ?>
<div class="news-box2">
<img class="news-img" src="<?= $new->img ?>" alt="">
<div class="news-title-g"><?= StringHelper::truncate($new->title,25,'...') ?></div>
</div>
<?php
$var = ob_get_contents();
ob_end_clean();
<?php $html = '<div class="news-box2">
<img class="news-img" src="<?= $new->img ?>" alt="">
<div class="news-title-g"><?= StringHelper::truncate($new->title,25,'"..."); ?></div>
</div>'; ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question