How to get first

from each of in an XML file?

Solution:

You can get the children of an element using the children() method. If you can guarantee that the first child will always be the element that you need, you can use it this way:

$title = $xml->channel->item[$i]->title;
$link = $xml->channel->item[$i]->link;
$description = $xml->channel->item[$i]->description->children();
$pubDate = $xml->channel->item[$i]->pubDate;

The children() function is meant to be used in an iterative manner, where every time you call it it returns the next child as a SimpleXMLElementhttp://php.net/manual/en/simplexmlelement.children.php

Edit
It seems that the cause of the issue are the <![CDATA[ ]]> tags. They cause the SimpleXMLElement to be empty. Stripping them fixes it:

$html = '';
$src = file_get_contents('http://sntsh.com/posts/feed/');
$search = ["<![CDATA[","]]>"];
$replace = array('','');
$data = str_replace($search,$replace,$src);
$xml = simplexml_load_string($data);

for($i = 0; $i < count($xml->channel->item); $i++)
{
    $title = $xml->channel->item[$i]->title;
    $link = $xml->channel->item[$i]->link;
    $description = $xml->channel->item[$i]->description->children();
    // Or
    // $description = $xml->channel->item[$i]->description->p[0];
    $pubDate = $xml->channel->item[$i]->pubDate;

    $html .= "<a href='$link'><h3>$title</h3></a>";
    $html .= trim($description).'...';
    $html .= "<br />$pubDate";
}
echo $html;