Detecting a class in div to add content with php


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">


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

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


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

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

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.

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

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
in them.

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

<?php echo $div_content; ?>