<?php
// $Id: multibyte.php,v 1.3 2006/10/26 23:38:10 ohwada Exp $

// 2006-10-26 K.OHWADA
// BUG 4339: Fatal error: Call to undefined function: strcut() 

// 2006-09-10 K.OHWADA
// this is new file

//=========================================================
// Happy Linux Framework Module
// 2006-09-01 K.OHWADA
//=========================================================

//---------------------------------------------------------
// subsutite for multibyte string fucntion
//---------------------------------------------------------

function happy_linux_convert_encoding( $str, $to, $from=null )
{
	if ( function_exists('mb_convert_encoding') )
	{
		if ($from)
		{
			return mb_convert_encoding($str, $to, $from);
		}
		else
		{
			return mb_convert_encoding($str, $to);
		}
	}
	return $str;
}

function happy_linux_convert_to_utf8($str, $encoding=null)
{
	if ( empty($encoding) )
	{
		$encoding = _CHARSET;
	}

	if ( function_exists('mb_convert_encoding') )
	{
		$str = mb_convert_encoding($str, 'UTF-8', $encoding);
	}
	else
	{
		$str = utf8_encode($str);
	}
	return $str;
}

function happy_linux_convert_from_utf8($str, $encoding=null)
{
	if ( empty($encoding) )
	{
		$encoding = _CHARSET;
	}

	if ( function_exists('mb_convert_encoding') )
	{
		$str = mb_convert_encoding($str, $encoding, 'UTF-8');
	}
	else
	{
		$str = utf8_decode($str);
	}
	return $str;
}

function happy_linux_convert_kana( $str, $option="KV", $encoding=null )
{
	if ( function_exists('mb_convert_kana') )
	{
		if ($encoding)
		{
			return mb_convert_kana( $str, $option, $encoding );
		}
		else
		{
			return mb_convert_kana( $str, $option );
		}
	}
	return $str;
}

function happy_linux_internal_encoding( $encoding=null )
{
	if ( function_exists('mb_internal_encoding') )
	{
		if ($encoding)
		{
			return mb_internal_encoding( $encoding );
		}
		else
		{
			return mb_internal_encoding();
		}
	}
}

function happy_linux_strcut( $str, $start, $length, $encoding=null )
{
	if ( function_exists('mb_strcut') )
	{
		if ($encoding)
		{
			return mb_strcut($str, $start, $length, $encoding);
		}
		else
		{
			return mb_strcut($str, $start, $length);
		}
	}

// BUG 4339: Fatal error: Call to undefined function: strcut() 
// strcut -> substr
	return substr($str, $start, $length);
}

function happy_linux_http_output( $encoding=null )
{
	if ( function_exists('mb_http_output') )
	{
		return mb_http_output($encoding);
	}
}

function happy_linux_send_mail($mailto, $subject, $message, $headers=null, $parameter=null)
{
	if ( function_exists('mb_send_mail') )
	{
		if ( $parameter )
		{
			return mb_send_mail($mailto, $subject, $message, $headers, $parameter);
		}
		elseif ( $headers )
		{
			return mb_send_mail($mailto, $subject, $message, $headers);
		}
		else
		{
			return mb_send_mail($mailto, $subject, $message);
		}
	}

	if ( $parameter )
	{
		return mail($mailto, $subject, $message, $headers, $parameter);
	}
	elseif ( $headers )
	{
		return mail($mailto, $subject, $message, $headers);
	}

	return mail($mailto, $subject, $message);
}

?>