value 110"; I ne...">

How to get HTML Div value using PHP

I have a div that php

. It is shown below.

$did = "<div id='primary'>value 110</div>";

      

I need a value in some variable just like 'value 110'

. I do not want to use Jquery

, Ajax

or any other javascript

.

I need the div value in a variable php

.

And also the value inside the Div, which is "value 110", comes through Jquery.So this is the runtime onclick value of the edit button.

+3


source to share


2 answers


PHP Simple HTML DOM Parser might be what you need, give it a try.

Here's an example that shows how to edit an HTML element:

$html = str_get_html('<div id="hello">Hello</div><div id="world">World</div>');

$html->find('div', 1)->class = 'bar';

$html->find('div[id=hello]', 0)->innertext = 'foo';

echo $html; // Output: <div id="hello">foo</div><div id="world" class="bar">World</div>

      



In this example, you can easily generate the code you need:

$html = str_get_html("<div id='primary'>value 110</div>");
$text = $html->find('div[id=primary]', 0)->innertext;
echo $text; // Prints "value 110", the content inside the div called "primary"

      

I haven't tried the code, but I believe it works shuold.

+1


source


use a function to make your divs

function divmaker($id, $value) 
{ 
echo '<div '; 
if(!empty($id))echo 'id='.$id;
echo '>'.$value.'</div>;
}

      



this way you can output divs and keep the value separately

0


source







All Articles