hello there. i was just wondering.is it possible to get the text display of your div and place it in a variable? if so, how should i do it? i've been searching for a solution in this problem but i can't find anything.thanks in advance.

Recommended Answers

All 2 Replies

You can use the PHP Document Object Model (DOM), an example:

<?php
    $f = '
    <html>
        <head>
            <title>test</title>
        </head>
        <body>
            <div id="aaa">apples</div>
            <div id="bbb">oranges</div>
        </body>
    </html>
        ';
    $dom = new domDocument;
    $dom->loadHTML($f);
    $dom->preserveWhiteSpace = false;
    
    $t = $dom->getElementsByTagName('div');
    $newElement = $t->item(0)->nodeValue; // 0 to display #aaa, 1 for #bbb
    echo $newElement . "\n";
?>

Thanks for the help cereal. i was trying to echo the website into $f, then pull the div by id. 1, how do i get the web content into a variable.. like $f = geturlcontent? then call the div. 2, can i use $t = $dom->getElementById($f); to get the div that i want? basically what im trying to do is get stats of players from one website and post it on mine. this way ppl can come to my website and view stats of players and not have to visit the original website

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.