I’m new to PHP but I think it’s possible, thought unsure how to achieve this.
I’ve got a basic HTML markup inside a PHP file called button.php which I’m injecting into a web page using PHP include.
Here’s the contents of the button.php file:
<div class="btn">
<div class="highlightBtn">
<div class="btnTag">
Submit
</div>
</div>
</div>
The question is – how do I the value inside the class=”btnTag” tags AFTER I’ve included it? (I.e. after I include this file into the main page I want to be able to change it depending on where it’s included, so it doesn’t always have to say ‘Submit’).
So I imagine it might be something like
<? php include("button.php");
//some code follows to change value inside the btnTag class
?>
Thanks for your help!
It really should be done beforehand, as in
And then
However, the above is not really a good approach
It would be much better to have the file just define a function when included, which you can then call whenever you need a button. For example:
You can then include
button.phpwithout any immediate effects, and whenever you want a button you can just callbutton('Click me')or justbutton().