Make PHP print names in certain classes [closed]

-3

The following JavaScript code has the print a text function on elements with the class exibir :

$(document).ready(function(){
        $(".exibir").text("Olá Mundo!");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><pclass="exibir">Isso é um parágrafo.</p>
<p class="exibir">Isso é um parágrafo.</p>

The code that I type "maqueia" the texts contained, I wanted to do the same, only in PHP, because I'm creating a page that needs to come printed from the server ( PHP ), instead of being changed after loaded page ( Javascript ).

  

How to do this same function in PHP ?

I'm creating a page that contains 4 equal texts in the body of the page.

I need somehow to set what will be displayed in these 4 texts in the page header, that is, there in the header " <head> " I can set via PHP , which will be displayed in these 4 identical texts that are in the body of the page " <body> ".

    
asked by anonymous 19.12.2016 / 08:23

1 answer

2

OJavaScript runs through the user's browser.

PHP runs on the so-called "backend", that is, it needs a request to the server where PHP is located.

There is no such function as in JavaScript, which can interact directly with the DOM of the HTML page displayed in the browser.

What I could do is, something like this:

$(document).ready(function(){
        $(".exibir").text("<?php echo $_GET['nome'];?>");
});

But it is not very clear what you really want because there are different ways to solve. The most appropriate way depends on the ultimate goal, beyond the circumstances involved.

    
19.12.2016 / 10:55