Jump to content

Xpath Code Snippets


tass2001

Recommended Posts

Hey im using the following code to snip out info from a myspace profile

 

<?php
$dom = new domdocument;

$url = 'http://www.myspace.com/yourprofile';

@$dom->loadHTMLFile($url);

$xpath = new domxpath($dom);
$xNodes = $xpath->query('//td');


echo '<ul>';
foreach ($xNodes as $xNode)
{
    $content = @$xNode->firstChild->data;
    $contentId = $xNode->getAttribute('id');

    if ($content != '' && $contentId != '')
    {
        echo $contentId;
      echo " - ";
      echo $content;
      echo '<br>';
    }
}
?>

 

But I would also like it to preform the following function


echo '<span style="font-size: 12px; font-family: Verdana">';
$pieces = explode("About me:(/span><br/>", $result);
$aboutme = $pieces[1];  $pieces = explode("<span class=\"text\"><div 

style=\"display:none;\">", $aboutme);
$aboutme = $pieces[1];  $pieces = explode("</div>", $aboutme);
$aboutme = $pieces[0];
$aboutme = str_replace("\r\n", "<br>", $aboutme);
echo "<b><u>About me</u></b>".$aboutme."<br>" ; # <-- missing

 

how would I do that?

Link to comment
https://forums.phpfreaks.com/topic/80679-xpath-code-snippets/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.