Skip to content Skip to sidebar Skip to footer

How To Get Value Of HTML Div Using PHP

I have div which is php.It is given below. $did = '
value 110
'; I need value in some variable as 'value 110' only.I don't want to use Jquery,Aja

Solution 1:

PHP Simple HTML DOM Parser may 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>

From the example you can easily create the code that 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 shuold work.


Solution 2:

use a function to make your divs

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

that way you can output divs and keep value separate


Post a Comment for "How To Get Value Of HTML Div Using PHP"