tjar
tjar

Reputation: 299

incorprating css and html elements into php

I have a bunch of php files that I want to incorporate html (divs) and css (external stylesheets) elements into.

If any one has any tips / ideas on how to go about doing this I'd love to hear them :)

Upvotes: 0

Views: 72

Answers (3)

DADU
DADU

Reputation: 7086

Take a look at the PHP alternative syntax for control structures. It is often times more comprehensive when you start mixing with plain HTML:

<?php if(...): ?>

<p>paragraph</p>

<?php endif; ?>

Instead of:

<?php if(...) { ?>

<p>paragraph</p>

<?php } ?>

Upvotes: 0

Ant
Ant

Reputation: 3887

All you need to do is exit php and write html as normal:

<?php
// php code
?>

<div>
  <p>Some html</p>
</div>

<?php
// more php code
?>

Upvotes: 1

Pascal MARTIN
Pascal MARTIN

Reputation: 401182

You could either :

  • Integrate HTML code in your PHP file,
  • Or have your PHP script echo the HTML content.


With the first solution, your PHP file could look like this :

<?php 
    $var = 10;
    // some PHP code
?>
<div>
    this is some HTML
</div>
<?php
    // and some PHP code again
?>

For more informations about this, see the following section of the manual : Escaping from HTML.


While, with the second solution, your PHP file could look like this :

<?php
    $var = 10;
    // some PHP code

    echo '<div>this is some HTML</div>';

    // and some PHP code again

?>


Basically, you are free to mix HTML and PHP code in the same PHP script : outside of <?php ... ?> tags, things will not get interpreted as PHP code.

Upvotes: 5

Related Questions