简体   繁体   中英

how to find value from html using PHP simple html dom parser

HOW TO GET THIS VALUE="NAME" FROM ABOVE CODE

i tried this code

<?php
// example of how to use basic selector to retrieve HTML contents
include('simple_html_dom.php');
// get DOM from URL or file
$html = file_get_html('sample.html');
$name = $html->find('.input-group #cpBody_txt_Data_UserName', 0)->innertext;
//echo $html->find('.ssoCitizenName #ssolbl_DisplayName', 0)->plaintext;
echo $name
// extract text from HTML

?>
<input name="ctl00$cpBody$txt_Data_UserName" type="text" autocomplete="off" value="JOHN DOE" maxlength="100" id="cpBody_txt_Data_UserName" tabindex="1" class="form-control">

i used this code to show value but getting blank page.

I NEED value="JOHN DOE" THIS IN output

You should use getAttribute function:

$name = $html->find('.input-group #cpBody_txt_Data_UserName', 0);
echo $name->getAttribute("value");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM