954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

div display pass to php variable

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.

shobe089
Newbie Poster
1 post since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

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";
?>
cereal
Master Poster
709 posts since Aug 2007
Reputation Points: 214
Solved Threads: 120
 

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

fobos
Posting Whiz in Training
297 posts since Feb 2009
Reputation Points: 29
Solved Threads: 52
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: