$url, CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_TIMEOUT => 10, CURLOPT_USERAGENT => "PHP cURL RSS Reader" ]); $response = curl_exec($ch); if (curl_errno($ch)) die("cURL error: " . curl_error($ch)); curl_close($ch); // Parse as XML $xml = @simplexml_load_string($response); if (!$xml) die("Failed to parse XML."); // Find first $firstTitle = ''; if (isset($xml->channel->item[0]->title)) { // RSS 2.0 style $firstTitle = (string)$xml->channel->item[0]->title; } elseif (isset($xml->entry[0]->title)) { // Atom style $firstTitle = (string)$xml->entry[0]->title; } elseif (isset($xml->title)) { // fallback $firstTitle = (string)$xml->title; } $text = str_replace($matches[0],$firstTitle,$text); } return $text; }