‘Share’ links generator

I don't know about you, but I spend far too much of my time creating those blasted 'Share' links. Well, I did, until I wrote this pair of handy functions.

They will create share links for Facebook, twitter, delicious and StumbleUpon on the fly. Additionally you can pass any URL to create a share link to, and a title if you like.

You can create more definitions very easily by adding to the $types array. Use the terms #URL# and #TITLE# for the URL and title, or #UURL# and #UTITLE# for the urlencode() versions.

function share($type=null,$url=null,$title=null){
	// I store various page data in an $args array.
	// For this function, I'm be using the page title.
	// If you don't have a page title, it'll be ignored.
	global $args;
	// Type definitions
		'tw'=>' #UURL#',
	// Sanity checks
	if(!$type)return 'NO TYPE REQUESTED';
	if(!array_key_exists($type,$types))return 'UNDEFINED TYPE REQUESTED';

	// Build the share link
	return str_replace($find,$replace,$types[$type]);
function thisurl(){
	// Return the full page URL

// Usage:
echo share('fb');
echo share('tw');
echo share('dl');
echo share('su');

PHP and Roman Numerals

After hunting around for functions that convert Arabic numbers to Roman numerals and vice versa, everything I found was huge (~100 lines) except for one very graceful function to convert Arabic numbers to Roman numerals. So I combined it with my own Roman to Arabic converter.

Pass it an int, a numeric string or a string of Roman numerals, and it will convert from one to the other.

Feel free to use the function in your own projects, but please keep the attributions intact.

function roman($num){
		'M' =>1000,
		'D' =>500,
		'C' =>100,
		'L' =>50,
		'X' =>10,
		'V' =>5,
		'I' =>1
		// To Roman:
		foreach($numerals as $roman=>$value){
		// To Arabic:
	return $result;

// Usage
echo roman('1000'); // M
echo roman(1100);   // MC
echo roman('MC');   // 1100
Filed under: PHP No Comments