Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Echo html that contains php

Tags:

html

php

I tried echoing something like:

<?php
echo '<div>Example Created to simplify <?php load(somefile.php); ?> </div>';
?>

It just displays Example Created to simplify.. Is there any way, simple modification of above, with which I can accomplish this.

I of course want to display Example Created to simplify and somefile.php. somefile.php and the text to not cover/block each other.

like image 453
user2178841 Avatar asked Feb 26 '26 07:02

user2178841


2 Answers

php is a server-side language. So it makes no sense to send php code to a client browser. Try it like this:

<?php
echo '<div>Example Created to simplify '.load(somefile.php).'</div>';
?>
like image 135
steven Avatar answered Feb 28 '26 20:02

steven


You don't have to open php tag again inside the string. Just use concatenation:

<?php
echo '<div>Example Created to simplify' . load(somefile.php) . '</div>';
?>

See also: PHP: String Operators

like image 41
Hast Avatar answered Feb 28 '26 21:02

Hast



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!