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>your name:<span>aaa</span></span>

php simple html dom parser api



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

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
$textarea = $html->find('textarea[class=textarea_getcode]'); 


something like that?

Saturday, May 29, 2021

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

you can get the html code using the snoopy class ( 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>
    <meta http-equiv="content-type" content="text/html; charset=euc-kr">
    <meta http-equiv="content-language" content="ko">
require("snoopy.class.php"); // ◄■■ get snoopy from
$snoopy = new snoopy;
$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.

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

Thursday, December 9, 2021
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 :