SimplePie 1.5 is now available!

SimplePie Documentation.  Learn how to use this thing.  It's way better than going to school.

You are here: Documentation » API Reference » SimplePie » set_cache_name_function()

set_cache_name_function()

Description

class SimplePie {
	set_cache_name_function ( [mixed $function = 'md5'] )
}

Set the callback function to create cache filename with.

Some operating systems (namely Windows) have filename length caps, and some feeds have a URL that is longer than that (eBay feeds, for example). By generating a shorter name, we not only protect the original URL, but we also avoid these types of filename errors.

Availability

  • Available since SimplePie 1.0.
  • Previously existed as set_cache_name_type() since SimplePie Beta 3.

Parameters

function

Callback function for naming cache files. The following is a list of built-in PHP functions suited for this, although you are free to write your own and use it here.

  • sha1 – Calculates the SHA1 hash using the US Secure Hash Algorithm 1. The hash is a 40-character hexadecimal number.
  • md5 – Calculates the MD5 hash using the MD5 Message-Digest Algorithm. The hash is a 32-character hexadecimal number.
  • crc32 – Generates the cyclic redundancy checksum polynomial of 32-bit lengths.
  • rawurlencode – Encodes the given string according to RFC 1738.
  • urlencode – Returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs.

Examples

Use SHA-1 to create cache filenames

$feed = new SimplePie();
$feed->set_feed_url('http://simplepie.org/blog/feed/');
$feed->set_cache_name_function('sha1');
$feed->init();
$feed->handle_content_type();
echo $feed->get_title();

Use custom function to create cache filenames

function pig_latin($string)
{
	$piglatin = '';
	// Code to convert string to Pig Latin...
	return $piglatin;
}
 
$feed = new SimplePie();
$feed->set_feed_url('http://simplepie.org/blog/feed/');
$feed->set_cache_name_function('pig_latin');
$feed->init();
$feed->handle_content_type();
echo $feed->get_title();

See Also


reference/simplepie/set_cache_name_function.txt · Last modified: 2011/03/06 03:56 (external edit)