<h2>รวม PHP Utils à¸à¸±à¸à¸à¹à¸à¸±à¹à¸à¸à¸£à¸£à¸à¸à¸£à¸°à¹à¸¢à¸à¸à¹à¸à¸µà¹à¹à¸à¹à¸à¸²à¸à¸à¹à¸à¸¢</h2>
<p></br><br />
<strong>รวม PHP Utils à¸à¸±à¸à¸à¹à¸à¸±à¹à¸à¸à¸£à¸£à¸à¸à¸£à¸°à¹à¸¢à¸à¸à¹à¸à¸µà¹à¹à¸à¹à¸à¸²à¸à¸à¹à¸à¸¢</strong></p>
<p>สำหรัà¸à¸à¸à¸à¸³à¹à¸§à¹à¸à¹à¸à¸à¹ à¹à¸à¹à¸à¸à¸à¸§à¹à¸²à¸à¸°à¸à¹à¸à¸à¸¡à¸µà¸à¸±à¸à¸à¹à¸à¸±à¹à¸à¸à¸²à¸à¸à¸¢à¹à¸²à¸à¸à¸µà¹à¸à¹à¸à¸à¹à¸à¹à¸à¸²à¸à¸à¸¢à¸¹à¹à¸à¹à¸à¸¢ ๠à¸à¸¶à¹à¸à¹à¸£à¸²à¸¡à¸±à¸à¸à¸°à¹à¸£à¸µà¸¢à¸à¸§à¹à¸² Utils function หรืà¸à¸à¸±à¸à¸à¹à¸à¸±à¹à¸à¸à¸£à¸£à¸à¸à¸£à¸°à¹à¸¢à¸à¸à¹ วัà¸à¸à¸µà¹à¹à¸à¹à¸£à¸§à¸à¸£à¸§à¸¡à¸à¸±à¸à¸à¹à¸à¸±à¹à¸à¸à¸µà¹à¸à¸³à¹à¸à¹à¸à¸ªà¸³à¸«à¸£à¸±à¸à¸à¸²à¸£à¸à¸±à¸à¸à¸²à¹à¸§à¹à¸à¹à¸à¸à¹à¹à¸à¹à¸à¹à¸§à¹à¹à¸à¸£à¸¹à¸à¹à¸à¸à¸à¸¥à¸²à¸ªà¸ªà¸²à¸¡à¸²à¸£à¸à¸à¸³à¹à¸à¹à¸à¹à¸à¸²à¸à¸à¹à¸à¸¢à¸à¸à¹à¸à¹à¹à¸¥à¸¢ ลà¸à¸à¸¡à¸²à¸à¸¹à¸à¸±à¸à¸à¸£à¸±à¸à¸§à¹à¸²à¸¡à¸µà¸à¸±à¸à¸à¹à¸à¸±à¹à¸à¸à¸°à¹à¸£à¸à¹à¸²à¸<!--more--></p>
<p></br></p>
<h4>à¸à¸±à¸§à¸à¸¢à¹à¸²à¸ PHP Utils à¸à¸±à¸à¸à¹à¸à¸±à¹à¸à¸à¸£à¸£à¸à¸à¸£à¸°à¹à¸¢à¸à¸à¹</h4>
<ul>
<li><strong>1. à¸à¸±à¸à¸à¹à¸à¸±à¹à¸à¹à¸à¸¥à¸ timestamp à¹à¸à¹à¸à¸à¸³à¸à¸§à¸±à¸à¹à¸§à¸¥à¸²à¹à¸à¸à¸¥à¸°à¹à¸à¸µà¸¢à¸</strong>
<pre class="lang:default decode:true " >function time_elapsed($datetime, $full = false) { 
		date_default_timezone_set("Asia/Bangkok"); 
		$now = new DateTime; 
		$ago = new DateTime($datetime); 
		$diff = $now->;diff($ago); 
		$diff->;w = floor($diff->;d / 7); 
		$diff->;d -= $diff->;w * 7; 
	 
		$string = array( 
			'y' =>; 'year', 
			'm' =>; 'month', 
			'w' =>; 'week', 
			'd' =>; 'day', 
			'h' =>; 'hour', 
			'i' =>; 'minute', 
			's' =>; 'second' 
		); 
		foreach ($string as $k =>; &;$v) { 
			if ($diff->;$k) { 
				$v = $diff->;$k . ' ' . $v . ($diff->;$k >; 1 ? 's' : ''); 
			} else { 
				unset($string[$k]); 
			} 
		} 
		 
		if (!$full) $string = array_slice($string, 0, 1); 
		$string = str_replace('months','à¹à¸à¸·à¸à¸',$string); 
		$string = str_replace('month','à¹à¸à¸·à¸à¸',$string); 
		$string = str_replace('weeks','สัà¸à¸à¸²à¸«à¹',$string); 
		$string = str_replace('week','สัà¸à¸à¸²à¸«à¹',$string); 
		$string = str_replace('days','วัà¸',$string); 
		$string = str_replace('day','วัà¸',$string); 
		$string = str_replace('hours','à¸à¸±à¹à¸§à¹à¸¡à¸',$string); 
		$string = str_replace('hour','à¸à¸±à¹à¸§à¹à¸¡à¸',$string); 
		$string = str_replace('minutes','à¸à¸²à¸à¸µ',$string); 
		$string = str_replace('minute','à¸à¸²à¸à¸µ',$string); 
		$string = str_replace('seconds','วิà¸à¸²à¸à¸µ',$string); 
		$string = str_replace('second','วิà¸à¸²à¸à¸µ',$string); 
		 
		return $string ? $string = implode(' ', $string) . ' à¸à¸µà¹à¹à¸¥à¹à¸§' : 'à¹à¸¡à¸·à¹à¸à¸ªà¸±à¸à¸à¸£à¸¹à¹'; 
	}</pre>
<p>วิà¸à¸µà¹à¸à¹à¸à¸²à¸à¹à¸¥à¸°à¸à¸¥à¸¥à¸±à¸à¸à¹à¹à¸¡à¸·à¹à¸à¹à¸£à¸µà¸¢à¸à¹à¸à¹à¸à¸²à¸</p>
<pre class="lang:default decode:true " >echo 'time_elapsed : '.Utils::time_elapsed($timestamp,true).'<;br>;'; 
time_elapsed : 8 à¹à¸à¸·à¸à¸ 4 สัà¸à¸à¸²à¸«à¹ 22 à¸à¸±à¹à¸§à¹à¸¡à¸ 46 à¸à¸²à¸à¸µ 25 วิà¸à¸²à¸à¸µ à¸à¸µà¹à¹à¸¥à¹à¸§</pre>
</li>
<li>
<strong>2. à¸à¸±à¸à¸à¹à¸à¸±à¹à¸à¹à¸à¸¥à¸à¸à¸±à¸§à¹à¸¥à¸à¹à¸à¹à¸à¸à¸±à¸§à¸¢à¹à¸</strong></p>
<pre class="lang:default decode:true " >function number_shorten($number, $precision = 3, $divisors = null) { 
		if (!isset($divisors)) { 
			$divisors = array( 
				pow(1000, 0) =>; '', 
				pow(1000, 1) =>; 'K', 
				pow(1000, 2) =>; 'M', 
				pow(1000, 3) =>; 'B', 
				pow(1000, 4) =>; 'T', 
				pow(1000, 5) =>; 'Qa', 
				pow(1000, 6) =>; 'Qi', 
			); 
		} 
		foreach ($divisors as $divisor =>; $shorthand) { 
			if (abs($number) <; ($divisor * 1000)) { 
				break; 
			} 
		} 
		return number_format($number / $divisor, $precision) . $shorthand; 
	}</pre>
<p>วิà¸à¸µà¹à¸à¹à¸à¸²à¸à¹à¸¥à¸°à¸à¸¥à¸¥à¸±à¸à¸à¹à¹à¸¡à¸·à¹à¸à¹à¸£à¸µà¸¢à¸à¹à¸à¹à¸à¸²à¸</p>
<pre class="lang:default decode:true " >echo 'number_shorten : '.Utils::number_shorten($thaibaht,0).'<;br>;'; 
number_shorten : 34K</pre>
</li>
</ul>
<p></br></p>
<h4>à¸à¸±à¸§à¸à¸¢à¹à¸²à¸à¸à¸±à¸à¸à¹à¸à¸±à¹à¸à¸à¸·à¹à¸ ๠à¹à¸ PHPUtils.php</h4>
<pre class="lang:default decode:true " > 
require_once("PHPUtils.php"); 
	 
$timestamp = '2016-11-15 14:53:23'; 
$thaibaht = 34000; 
	 
echo 'time_elapsed : '.Utils::time_elapsed($timestamp,true).'<;br>;'; // à¹à¸à¸¥à¸ timestamp à¹à¸à¹à¸à¸à¸³à¸à¸§à¸à¸§à¸±à¸à¹à¸§à¸¥à¸²à¸à¸µà¹à¸à¹à¸²à¸à¸¡à¸² 
echo 'number_shorten : '.Utils::number_shorten($thaibaht,0).'<;br>;'; // à¹à¸à¸¥à¸à¸à¸±à¸§à¹à¸¥à¸à¹à¸à¹à¸à¸à¸±à¸§à¸¢à¹à¸ 
echo 'random_code : '.Utils::random_code(10).'<;br>;'; // สุà¹à¸¡à¸£à¸«à¸±à¸ªà¸à¸±à¸§à¹à¸¥à¸ à¸à¸±à¸§à¸à¸±à¸à¸©à¸£ 
echo 'get_thai_date : '.Utils::get_thai_date($timestamp).'<;br>;'; // à¹à¸à¸¥à¸ timestamp à¹à¸à¹à¸à¸§à¸±à¸à¹à¸à¸·à¸à¸à¸à¸µà¹à¸à¸¢ 
echo 'day_diff : '.Utils::day_diff($timestamp).'<;br>;'; // หาà¸à¸³à¸à¸§à¸à¸§à¸±à¸à¸à¸µà¹à¸à¹à¸²à¸à¸¡à¸²à¸à¸²à¸ timestamp 
echo 'get_client_ip : '.Utils::get_client_ip().'<;br>;'; // หาà¹à¸à¸à¸µà¹à¸à¸£à¸·à¹à¸à¸</pre>
<p></br><br />
สำ Web Developer à¸à¸µà¹à¸à¸±à¸à¸à¸²à¹à¸§à¹à¸à¹à¸à¸à¹à¸à¹à¸§à¸¢ codeigniter สามารà¸à¸à¸³à¸à¸¥à¸²à¸ª PHPUtils.php à¹à¸à¸§à¸²à¸à¹à¸§à¹à¹à¸à¸ªà¹à¸§à¸à¸à¸à¸ libraries à¸à¸²à¸à¸à¸±à¹à¸à¸ªà¸²à¸¡à¸²à¸£à¸à¹à¸à¸´à¸à¹à¸à¹à¸à¸²à¸à¸à¸¥à¸²à¸ªà¹à¸à¹ 2 à¸à¹à¸à¸à¸à¸²à¸à¸à¸±à¸à¸à¸µà¹<br />
<strong>à¹à¸£à¸µà¸¢à¸à¹à¸à¹à¸à¸²à¸à¹à¸à¸ªà¹à¸§à¸à¸à¸à¸ controller </strong></p>
<pre class="lang:default decode:true " >$this->;load->;library('phputils'); </pre>
<p><strong>à¹à¸£à¸µà¸¢à¸à¹à¸à¹à¸à¸²à¸à¸à¹à¸²à¸ autoload</strong></p>
<pre class="lang:default decode:true " >$autoload['libraries'] = array('phputils');</pre>
<p></br></p>
<blockquote><p><a href="http://codebee.co.th/labs/examples/PHPUtils.php.zip" target="_blank">à¸à¸²à¸§à¸à¹à¹à¸«à¸¥à¸ PHPUtils.php.zip </a></p></blockquote>
<p></br></p>

รวม PHP Utils ฟังก์ชั่นอรรถประโยชน์ที่ใช้งานบ่อย

รวม-PHP-Utils-ฟังก์ชั่นอรรถประโยชน์ที่ใช้งานบ่อย
