Get id text of curtain element in PHP
I need to parse text from an h3 element in an HTML page and store the text in a variable.
<h3 class="names-header">Names</h3>
I need the output:
Names
Saved to a variable of type
$text = $output;
I've tried using the DOM, in particular this example , but I had no luck.
I was also trying to fetch data using JQuery and send it as a post using Ajax on the same page. Then capture the message and store it in PHP. It didn't work either, and it seems like there is a much faster way to do it.
I've googled and tried for about 2 hours and still can't figure out how to fix this. Any help / advice would be greatly appreciated right now. Thank.
source to share
it would be easy to use jquery for this! just use ajax
like in the following code.
$.ajax({
type: 'POST',
url:'your php page',
data:{name: $('.names-header').text()},
success:function(response){
alert(response);
}
})
in php do the following.
if(isset($_POST['name'])){
echo $_POST['name'];
}else{
echo 'no data to show';
}
this will allow you to catch the message data and do what you want.
source to share