: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Returns an associative array of name/value pairs, where the value is an
* array of values that have used the same name
* @param string $str The input string.
public static function parse_str($str)
$str = explode('&', $str);
foreach ($str as $section)
if (strpos($section, '=') !== false)
list($name, $value) = explode('=', $section, 2);
$return[urldecode($name)][] = urldecode($value);
$return[urldecode($section)][] = null;
* Detect XML encoding, as per XML 1.0 Appendix F.1
* @todo Add support for EBCDIC
* @param string $data XML data
* @param SimplePie_Registry $registry Class registry
* @return array Possible encodings
public static function xml_encoding($data, $registry)
if (substr($data, 0, 4) === "\x00\x00\xFE\xFF")
$encoding[] = 'UTF-32BE';
// UTF-32 Little Endian BOM
elseif (substr($data, 0, 4) === "\xFF\xFE\x00\x00")
$encoding[] = 'UTF-32LE';
elseif (substr($data, 0, 2) === "\xFE\xFF")
$encoding[] = 'UTF-16BE';
// UTF-16 Little Endian BOM
elseif (substr($data, 0, 2) === "\xFF\xFE")
$encoding[] = 'UTF-16LE';
elseif (substr($data, 0, 3) === "\xEF\xBB\xBF")
// UTF-32 Big Endian Without BOM
elseif (substr($data, 0, 20) === "\x00\x00\x00\x3C\x00\x00\x00\x3F\x00\x00\x00\x78\x00\x00\x00\x6D\x00\x00\x00\x6C")
if ($pos = strpos($data, "\x00\x00\x00\x3F\x00\x00\x00\x3E"))
$parser = $registry->create('XML_Declaration_Parser', array(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 20), 'UTF-32BE', 'UTF-8')));
$encoding[] = $parser->encoding;
$encoding[] = 'UTF-32BE';
// UTF-32 Little Endian Without BOM
elseif (substr($data, 0, 20) === "\x3C\x00\x00\x00\x3F\x00\x00\x00\x78\x00\x00\x00\x6D\x00\x00\x00\x6C\x00\x00\x00")
if ($pos = strpos($data, "\x3F\x00\x00\x00\x3E\x00\x00\x00"))
$parser = $registry->create('XML_Declaration_Parser', array(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 20), 'UTF-32LE', 'UTF-8')));
$encoding[] = $parser->encoding;
$encoding[] = 'UTF-32LE';
// UTF-16 Big Endian Without BOM
elseif (substr($data, 0, 10) === "\x00\x3C\x00\x3F\x00\x78\x00\x6D\x00\x6C")
if ($pos = strpos($data, "\x00\x3F\x00\x3E"))
$parser = $registry->create('XML_Declaration_Parser', array(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 10), 'UTF-16BE', 'UTF-8')));
$encoding[] = $parser->encoding;
$encoding[] = 'UTF-16BE';
// UTF-16 Little Endian Without BOM
elseif (substr($data, 0, 10) === "\x3C\x00\x3F\x00\x78\x00\x6D\x00\x6C\x00")
if ($pos = strpos($data, "\x3F\x00\x3E\x00"))
$parser = $registry->create('XML_Declaration_Parser', array(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 10), 'UTF-16LE', 'UTF-8')));
$encoding[] = $parser->encoding;
$encoding[] = 'UTF-16LE';
// US-ASCII (or superset)
elseif (substr($data, 0, 5) === "\x3C\x3F\x78\x6D\x6C")
if ($pos = strpos($data, "\x3F\x3E"))
$parser = $registry->create('XML_Declaration_Parser', array(substr($data, 5, $pos - 5)));
$encoding[] = $parser->encoding;
public static function output_javascript()
if (function_exists('ob_gzhandler'))
ob_start('ob_gzhandler');
header('Content-type: text/javascript; charset: UTF-8');
header('Cache-Control: must-revalidate');
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 604800) . ' GMT'); // 7 days
function embed_quicktime(type, bgcolor, width, height, link, placeholder, loop) {
document.writeln('<embed type="'+type+'" style="cursor:hand; cursor:pointer;" href="'+link+'" src="'+placeholder+'" width="'+width+'" height="'+height+'" autoplay="false" target="myself" controller="false" loop="'+loop+'" scale="aspect" bgcolor="'+bgcolor+'" pluginspage="http://www.apple.com/quicktime/download/"></embed>');
document.writeln('<embed type="'+type+'" style="cursor:hand; cursor:pointer;" src="'+link+'" width="'+width+'" height="'+height+'" autoplay="false" target="myself" controller="true" loop="'+loop+'" scale="aspect" bgcolor="'+bgcolor+'" pluginspage="http://www.apple.com/quicktime/download/"></embed>');
function embed_flash(bgcolor, width, height, link, loop, type) {
document.writeln('<embed src="'+link+'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="'+type+'" quality="high" width="'+width+'" height="'+height+'" bgcolor="'+bgcolor+'" loop="'+loop+'"></embed>');
function embed_flv(width, height, link, placeholder, loop, player) {
document.writeln('<embed src="'+player+'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" quality="high" width="'+width+'" height="'+height+'" wmode="transparent" flashvars="file='+link+'&autostart=false&repeat='+loop+'&showdigits=true&showfsbutton=false"></embed>');
function embed_wmedia(width, height, link) {
document.writeln('<embed type="application/x-mplayer2" src="'+link+'" autosize="1" width="'+width+'" height="'+height+'" showcontrols="1" showstatusbar="0" showdisplay="0" autostart="0"></embed>');
* Get the SimplePie build timestamp
* Uses the git index if it exists, otherwise uses the modification time
public static function get_build()
$root = dirname(dirname(__FILE__));
if (file_exists($root . '/.git/index'))
return filemtime($root . '/.git/index');
elseif (file_exists($root . '/SimplePie'))
foreach (glob($root . '/SimplePie/*.php') as $file)
if (($mtime = filemtime($file)) > $time)
elseif (file_exists(dirname(__FILE__) . '/Core.php'))
return filemtime(dirname(__FILE__) . '/Core.php');
return filemtime(__FILE__);
* Format debugging information
public static function debug(&$sp)
$info = 'SimplePie ' . SIMPLEPIE_VERSION . ' Build ' . SIMPLEPIE_BUILD . "\n";
$info .= 'PHP ' . PHP_VERSION . "\n";
if ($sp->error() !== null)
$info .= 'Error occurred: ' . $sp->error() . "\n";
$info .= "No error found.\n";
$info .= "Extensions:\n";
$extensions = array('pcre', 'curl', 'zlib', 'mbstring', 'iconv', 'xmlreader', 'xml');
foreach ($extensions as $ext)
if (extension_loaded($ext))
$info .= " $ext loaded\n";
$info .= ' Version ' . PCRE_VERSION . "\n";
$version = curl_version();
$info .= ' Version ' . $version['version'] . "\n";
$info .= ' Overloading: ' . mb_get_info('func_overload') . "\n";
$info .= ' Version ' . ICONV_VERSION . "\n";
$info .= ' Version ' . LIBXML_DOTTED_VERSION . "\n";
$info .= " $ext not loaded\n";
public static function silence_errors($num, $str)
* Sanitize a URL by removing HTTP credentials.
* @param string $url the URL to sanitize.
* @return string the same URL without HTTP credentials.
public static function url_remove_credentials($url)
return preg_replace('#^(https?://)[^/:@]+:[^/:@]+@#i', '$1', $url);