Asked  1 Year ago    Answers:  5   Viewed   26 times

how can i get the text value where <span>your name:<span> with the php simple html dom parser without children command?

<div class="adds-info">
    <span>price:<span>1000000000 </span></span>
    <span>txt1</span>
    <span>your name:<span>aaa</span></span>
    <span>phone:<span>02632402210</span></span>
</div>

php simple html dom parser api

 Answers

1

thank you defines, i try by this and works

$spans = '.adds-info span';
foreach($spans as $n){  
                        if (strpos($n->innertext, "your name:") !== false) {
                            $name = $n->innertext;
                            $name = str_replace('your name:', '', $name);
                            echo "name: " . $name  . "<hr>";
                        }
                    }
Saturday, May 29, 2021
 
5

first, what i would do is also iterate each td's thru foreach. so that you'll be able to get which index number key it falls into. (note that of course its indexing is zero based so it actually starts at 0).

then inside the inner loop, just check if the class is null, then map it in the corresponding word 1 = one, 2 = two, etc...

rough example:

$map = array(1 => 'one', 2 => 'two', 3 => 'three');
foreach ($demo->find('tr') as $tr) { // loop each table row
    // then loop each td
    foreach($tr->find('td') as $i => $td) { // indexing starts at zero
        if($td->class == 'null') { // if its class is null
            echo $map[$i+1]; // map it to its corresponding word equivalent
        }
    }
}

so in this case, this would output three and then two. inside the second table row, the null lands on the third, inside the third row it lands into the second.

Thursday, April 1, 2021
 
muffe
 
1
$textarea = $html->find('textarea[class=textarea_getcode]'); 

$textarea->innertext;

something like that?

Saturday, May 29, 2021
 
Sidarta
 
5

no, simple html dom doesn't do dom manipulation. with phpquery though you can do:

$doc->find('head')->append('<script src="foo"></script>');
Friday, November 12, 2021
 
2

you can get the html code using the snoopy class (https://sourceforge.net/projects/snoopy). next code displays the html code inside of a <textarea> tag, then it displays the page itself, copy-paste next code in a php file and open it in your browser:

<!doctype html>
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=euc-kr">
    <meta http-equiv="content-language" content="ko">
  </head>
  <body>
<?php
require("snoopy.class.php"); // ◄■■ get snoopy from https://sourceforge.net/projects/snoopy
$snoopy = new snoopy;
$snoopy->fetch("http://eecs.kookmin.ac.kr/site/computer/notice.htm");
$html = mb_convert_encoding( $snoopy->results, "utf-8", "euc-kr" ); // ◄■■ get html code.
echo "<textarea rows='25' cols='80'>$html</textarea>"; // ◄■■ display the html.
echo $html; // ◄■■ display the webpage.
?>
  </body>
</html>

the snoopy class is only one file, make sure the file is in the same directory your php file is.

Thursday, December 9, 2021
 
juherr
 
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :