1

I'm making a website and it'll have a user page on which will be user score. I'm taking that score from the other website but the problem is how to do that: how to get text from any element on any website? I wanted to try this but I don't know how to select that th from which I need text because the whole table hasn't any IDs, only a class. You can see in the code, I want text from the place where is written: I NEED THIS.

Thanks.

<table class="profile" style="padding:0px; margin:0px;">
    <tr>
        <td valign="top" style="padding:0px; margin:0px;">
            <h3>TEXT</h3>
        </td>
        <td valign="bottom" align="right">
            TEXT</br>
            TEXT</br>
        </td>
    </tr>
    <tr>
        <td valign="top">
        <table class="score_stats">
            <tr><th>TEXT</th><th>   **I NEED THIS**   </th></tr>
            <tr><td>TEXT</td><td>NUMBER</td></tr>
            <tr><td>TEXT</td><td>NUMBER</td></tr>
            <tr><td>TEXT</td><td>NUMBER</td></tr>
            <tr><td>TEXT</td><td>NUMBER</td></tr>
            <tr><td>TEXT</td><td>NUMBER</td></tr>
       </table>
       </td>
    </tr>
</table>
Community
  • 1
  • 1
valek
  • 1,365
  • 16
  • 27

2 Answers2

1
  1. Get the html code of the page , in string or array Many choices here >>How do I get the HTML code of a web page in PHP?

2.Split those strings or things you need with some simple code , I know you could find it by yourself

Hope this helps

Poom

Community
  • 1
  • 1
Poomrokc The 3years
  • 1,099
  • 2
  • 10
  • 23
1

After the whole day of trying I made this:

function getPlayerScore($url){
    libxml_use_internal_errors( true );
    $dom = new DOMDocument();
    $dom->loadHTMLFile( $url );
    $finder = new DOMXpath( $dom );
    $nodes = $finder->query( "//*[@class='score_stats']/tr" )->item(0)->nodeValue;
    $nodes = str_split($nodes, 11);
    return $nodes[1];
}

getPlayerScore($user['playercp'])

...and it's working.

valek
  • 1,365
  • 16
  • 27