Detecting a class in div to add content with php

Hi.

I know that this can be done with JQuery, but I would prefer to implement it with PHP.

Is it possible to detect a class as a part of a div to insert content?

This code:


<div id="tag" class="box">

</div>

Then, an additional class is added when the tag is active


<div id="box1" class="box  active">

</div>

Is it possible to detect the “active” class inside “box1” and insert the content by php?


<div id="box1" class="box  active">
added content
</div>

Thanks very much.

You have it backwards. Javascript is able to “detect” and make a change as its client side. PHP is server side, so it has the privilege of already knowing where the div is going to be.


<html>
<div id="box1">
<?php echo "added content"; ?>
<div>
</html>

I suppose you could parse the markup and use PHP to add the content then serve the page.
But IMHO if you really want to do this server-side I’d look into using template PHP files that have something like
get_content(‘342’);
in them.

Or similar to Kyle’s example
$div_content = get_content(‘745’);

<?php echo $div_content; ?>