<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>jQueryTips by Tee++; &#187; API</title>
	<atom:link href="http://www.jquerytips.com/tag/api/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jquerytips.com</link>
	<description>Coding is fun.</description>
	<lastBuildDate>Sun, 25 Apr 2010 11:30:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>มา Translate กันเถอะ พี่ GG เค้าจัดมาแล้ว</title>
		<link>http://www.jquerytips.com/2009/03/06/jquery-with-gogole-translate/</link>
		<comments>http://www.jquerytips.com/2009/03/06/jquery-with-gogole-translate/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 16:36:05 +0000</pubDate>
		<dc:creator>Tee++;</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Others]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Gogole]]></category>
		<category><![CDATA[Jsonp]]></category>

		<guid isPermaLink="false">http://www.jquerytips.com/?p=261</guid>
		<description><![CDATA[Google Translate
ว้าว ขณะที่ Post ข้อความอยู่นี้ เชื่อมั้ยครับว่าผมเขียนบทความ ลงใน jQueryTips นี้ทั้งหมดกี่บทความแล้ว 80 !!!!! ใช่แล้วตั้ง 80 แน่ะ รวมบทความนี้ก็จะเป็นบทความที่ 81 ไม่น่าเชื่อเลย ว่าตัวเองจะเขียนได้มาไกลถึงขนาดนี้ 555++ 
ตอนแรกก็กะเขียนเล่นๆ คิดว่า วัน สองวันตัวเอง คงเบื่อ ไปๆมาๆ นี่เขียนกันเป็นปีเลย อืมม์ คิดๆแล้วก็ ภูมิใจแฮะ วันนี้เดี๋ยว export มา backup ซะหน่อยดีกว่า ^^
เอาล่ะๆ มาเข้าเรื่องที่จะเขียนวันนี้กันเลยดีกว่า &#8220;ภาษาอังกฤษ&#8221; -*- เชื่อแน่ๆ เลยครับว่าปัญหาเรื่อง ภาษา ไม่แข็งแรงนั้น สั่งสมอยู่กับคนไทย มานานแสนนาน ทำให้เราขาดโอกาส และการเรียนรู้ที่ดีๆ จาก international website, e-book หรือสื่อ ภาษาต่างประเทศ อะไรต่อมิอะไรไปไม่ใช่น้อย
แต่ผมคิดว่า ต่อไปนี้ปัญหาอาจจะเบาบางลง ด้วยท่านเทพแห่งโลกไซเบอร์อย่างพี่ [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.jQueryTips.com/example/GTranslate/" target="_blank">Google Translate</a></p>
<p>ว้าว ขณะที่ Post ข้อความอยู่นี้ เชื่อมั้ยครับว่าผมเขียนบทความ ลงใน jQueryTips นี้ทั้งหมดกี่บทความแล้ว 80 !!!!! ใช่แล้วตั้ง 80 แน่ะ รวมบทความนี้ก็จะเป็นบทความที่ 81 ไม่น่าเชื่อเลย ว่าตัวเองจะเขียนได้มาไกลถึงขนาดนี้ 555++ </p>
<p>ตอนแรกก็กะเขียนเล่นๆ คิดว่า วัน สองวันตัวเอง คงเบื่อ ไปๆมาๆ นี่เขียนกันเป็นปีเลย อืมม์ คิดๆแล้วก็ ภูมิใจแฮะ วันนี้เดี๋ยว export มา backup ซะหน่อยดีกว่า ^^</p>
<p>เอาล่ะๆ มาเข้าเรื่องที่จะเขียนวันนี้กันเลยดีกว่า &#8220;ภาษาอังกฤษ&#8221; -*- เชื่อแน่ๆ เลยครับว่าปัญหาเรื่อง ภาษา ไม่แข็งแรงนั้น สั่งสมอยู่กับคนไทย มานานแสนนาน ทำให้เราขาดโอกาส และการเรียนรู้ที่ดีๆ จาก international website, e-book หรือสื่อ ภาษาต่างประเทศ อะไรต่อมิอะไรไปไม่ใช่น้อย</p>
<p>แต่ผมคิดว่า ต่อไปนี้ปัญหาอาจจะเบาบางลง ด้วยท่านเทพแห่งโลกไซเบอร์อย่างพี่ <a href="http://www.google.com">Big Google</a> เพราะตอนนี้ ท่านได้ออก Language Service ชุดของการ Translate ใน version th -> en, en -> th หรือ ภาษาอื่นๆ อีกเยอะแยะมาแล้ว<span id="more-261"></span></p>
<p>จะแปลทั้งเวบ หรือจะแปลเป็นประโยค ก็สะดวกสบาย รวดเร็ว ไปลองกันดูได้ ที่นี่ <a href="http://translate.google.co.th/">Google Translate</a></p>
<p>เห็นมั้ย เจ๋งโครต แต่ถ้าคิดว่าวันนี้ ผมจะมาแนะนำ Service แค่นี้ล่ะก็ ผิดถนัดครับ ผมมีอะไรๆ ทีเด็ดกว่านี้เยอะรอให้ไปอ่านกันอยู่แล้ว&#8230;&#8230;</p>
<p>รู้มั้ยครับว่า <a href="http://code.google.com/apis/ajaxlanguage/documentation/">Google AJAX Language</a> ก็มี <a href="http://code.google.com/apis/ajaxlanguage/documentation/">API</a> ด้วย ซึ่งการใช้งานก็โครตจะง่าย เพราะมันถูก plug เข้ามาอยู่ในชุดของ Google JS API แล้ว ทำให้เราเรียกโหลดมาจาก Google ได้เลย โดยไม่จำเป็นต้องมา include อะไรวุ่นวาย </p>
<p>ไม่เชื่อเอาโคดชุดนี้ไปรันดู</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&lt;html&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;head&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;script type=&quot;text/javascript&quot; src=&quot;http://www.google.com/jsapi&quot;&gt;&lt;/script&gt;
</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &lt;script type=&quot;text/javascript&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; google.load(&quot;language&quot;, &quot;1&quot;);
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; function translate() {
</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; var text = document.getElementById(&quot;text&quot;).innerHTML;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; google.language.detect(text, function(result) {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; if (!result.error &amp;&amp; result.language) {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; google.language.translate(text, result.language, &quot;en&quot;,
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function(result) {
</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var translated = document.getElementById(&quot;translation&quot;);
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (result.translation) {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; translated.innerHTML = result.translation;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });
</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; }
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; });
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; }
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;/script&gt;
</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &lt;/head&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;body&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;div&gt;&lt;span id=&quot;text&quot;&gt;สวัสดี ชาวโลก&lt;/span&gt;&lt;input type=&quot;button&quot; value=&quot;translate&quot; onclick=&quot;translate()&quot; /&gt;&lt;/div&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;div id=&quot;translation&quot;&gt;&lt;/div&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;/body&gt;
</div>
</li>
<li class="li2">
<div class="de2">&lt;/html&gt;</div>
</li>
</ol>
</div>
<p>ซึ่งใน API ชุดนี้ของ GG จะประกอบไปด้วย สองส่วนหลักๆก็คือ<br />
1. Detect language<br />
ตัวนี้เป็นตัวตรวจสอบภาษาที่จะแปลครับ ว่าเป็นภาษาอะไร โดยเราไม่จำเป็นต้องบอก GG ว่าเรากำลังจะแปลจาก ภาษาอะไรเป็นภาษาอะไร โดยแค่เราส่ง กลุ่มที่จะแปลเข้าไป GG จะบอกมาเองว่าเรากำลังทำงานกับภาษาอะไร จะคืนค่าเป็น th, en, jp หรือ ภาษาอื่นๆ</p>
<p>2. Translate<br />
แน่นอนอีกตัวคือหัวใจครับ ตัวแปลนั่นเอง โดยตัวแปลนี้เราสามารถส่ง text เข้าไปแปล โดยต้องระบุ </p>
<p>text = ประโยคที่จะทำการแปล<br />
source = แปลจากภาษาอะไร เช่น en (ตรงนี้เราจะสามารถใช้ api ชุด detect lang ทำงานแทนได้)<br />
destination = แปลมาเป็นภาษาอะไร เช่น th</p>
<p>ซึ่งจากที่ผมเอา Firebug จับมา การทำงานของ API Google ชุดนี้ก็คือ JSONP นั่นเอง</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">http://www.google.com/uds/Gtranslate?callback=google.language.callbacks.id101&amp;context=22&amp;q=สวัสดีชาวโลก&amp;langpair=th|en&amp;key=notsupplied&amp;v=1.0</div>
</li>
</ol>
</div>
<p>เอาล่ะๆ ไอ้ที่บอกมาทั้งหมด มันแค่เกริ่นเท่านั้นเองอ่ะ ที่เป็นบทความวันนี้จริงๆ มันต้องเป็น jQuery แน่นอนอยู่แล้ว นี่ครับ</p>
<p><a href="http://sundaymorning.jaysalvat.com/">Sunday Morning jQuery Google Translate API</a></p>
<p>ซึ่งหน้าตาโดยรวมแล้ว ให้ 9/10 ครับ สวยงามน่าใช้ แถมใช้งานง่ายด้วย สามารถแปลแบบ กลุ่มคำ หรือแบบ คำเดี่ยวก็ได้ ใช้เป็น Dict ภายในเวบเลยก็ยังได้</p>
<p>ยังไงก็ลองไปเล่นกันดูนะครับ ผมคงไม่เขียนอธิบายวิธีใช้ เพราะเค้าเขียนไว้หมดแล้ว ไม่เข้าใจยังไง view source ดูกันเอาก็น่าจะพอเข้าใจอยู่ ตัวนี้ส่วนตัวผมถือว่าเป็น <strong>Plugin น้ำดี</strong> ตัวนึงเลยทีเดียว </p>
<p>อันนี้เป็นตัวอย่างที่ผมลองเอามาเขียนเล่นๆครับ</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">http://www.jQueryTips.com/example/GTranslate/</div>
</li>
</ol>
</div>
<p>เอ แต่ถ้าอ่าน เว็บเค้าแล้วไม่เข้าใจ ก็ลองอย่าลืมใช้ Google Translate มาเป็นภาษาแม่ เราดูนะครับ 555++ </p>
<p>วันนี้ลาไปก่อนแค่นี้ล่ะ จะไปแรดข้างนอกละ ^^</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jquerytips.com/2009/03/06/jquery-with-gogole-translate/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>ลองมาแล้ว Yahoo! Search BOSS</title>
		<link>http://www.jquerytips.com/2008/07/14/yahoo-search-boss/</link>
		<comments>http://www.jquerytips.com/2008/07/14/yahoo-search-boss/#comments</comments>
		<pubDate>Mon, 14 Jul 2008 16:39:39 +0000</pubDate>
		<dc:creator>Tee++;</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[API]]></category>

		<guid isPermaLink="false">http://www.jquerytips.com/2008/07/14/yahoo-search-boss/</guid>
		<description><![CDATA[&#8220;BOSS (Build your Own Search Service)&#8221; API ใหม่แจ่มๆ จาก Yahoo ผมจะไม่ขอพูดถึง ข้อดีข้อเสียอะไรนะแล้วกัน มันต้องไปลองใช้ แล้ว วิเคราะห์กันเอาเอง แต่จะมาบอกถึงขั้นตอนการใช้งาน และ implement เลย
ก่อนอื่นก็ไปสมัคร API Key กันมาก่อน ที่นี่ จากนั้นได้มาแล้วมาทำตามข้างล่างกัน 
จากนั้นลองมา implement กันดู เช่นผมจะทำ เกี่ยวกับเรื่องของการ Search Web ก็เรียกง่ายๆ ไม่ยุ่งยากอะไร



http://boss.yahooapis.com/ysearch/web/v1/&#60;strong&#62;jquerytips.com&#60;/strong&#62;?AppID=YOUR_APP_ID&#38;format=xml



เท่านี้ผมก็จะได้ xml ที่เป็นข้อมูลที่ผมต้องการค้นหา มาทันทีแล้วนำไปใช้ต่อได้เลย ไม่ยุ่งยาก
ส่วน Arguments ต่างที่ ใส่ไปได้ก็ดูที่นี่
http://developer.yahoo.com/search/boss/boss_guide/univer_api_args.html
ถ้าอยากลองเล่นอย่างละเอียดก็ดูข้อมูลที่ทาง Yahoo! จัดทำไว้ได้เลย
http://developer.yahoo.com/search/boss/boss_guide
API ชุดนี้ของ Yahoo เค้ามันง่ายจริงๆ ครับ api ที่ผมใช้ส่วนใหญ่มักจะต้อง post ค่าผ่าน SOAP, XMLRPC, CURL หรือ อื่นๆ [...]]]></description>
			<content:encoded><![CDATA[<p>&#8220;BOSS (Build your Own Search Service)&#8221; API ใหม่แจ่มๆ จาก Yahoo ผมจะไม่ขอพูดถึง ข้อดีข้อเสียอะไรนะแล้วกัน มันต้องไปลองใช้ แล้ว วิเคราะห์กันเอาเอง แต่จะมาบอกถึงขั้นตอนการใช้งาน และ implement เลย</p>
<p>ก่อนอื่นก็ไปสมัคร API Key กันมาก่อน <a href="http://developer.yahoo.com/wsregapp/" target="_blank">ที่นี่</a> จากนั้นได้มาแล้วมาทำตามข้างล่างกัน <span id="more-42"></span></p>
<p>จากนั้นลองมา implement กันดู เช่นผมจะทำ เกี่ยวกับเรื่องของการ Search Web ก็เรียกง่ายๆ ไม่ยุ่งยากอะไร</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">http://boss.yahooapis.com/ysearch/web/v1/&lt;strong&gt;jquerytips.com&lt;/strong&gt;?AppID=YOUR_APP_ID&amp;format=xml</div>
</li>
</ol>
</div>
<p>เท่านี้ผมก็จะได้ xml ที่เป็นข้อมูลที่ผมต้องการค้นหา มาทันทีแล้วนำไปใช้ต่อได้เลย ไม่ยุ่งยาก</p>
<p>ส่วน Arguments ต่างที่ ใส่ไปได้ก็ดูที่นี่<br />
<a href="http://developer.yahoo.com/search/boss/boss_guide/univer_api_args.html" target="_blank">http://developer.yahoo.com/search/boss/boss_guide/univer_api_args.html</a></p>
<p>ถ้าอยากลองเล่นอย่างละเอียดก็ดูข้อมูลที่ทาง Yahoo! จัดทำไว้ได้เลย<br />
<a href="http://developer.yahoo.com/search/boss/boss_guide" target="_blank">http://developer.yahoo.com/search/boss/boss_guide</a></p>
<p>API ชุดนี้ของ Yahoo เค้ามันง่ายจริงๆ ครับ api ที่ผมใช้ส่วนใหญ่มักจะต้อง post ค่าผ่าน SOAP, XMLRPC, CURL หรือ อื่นๆ แต่ตัวนี้มันแค่ pass parameters ผ่าน query ไปไม่กี่ตัวก็ได้ค่ามาหมดแล้ว ที่สำคัญมันยังคืนค่ามาได้หลาย format เช่น</p>
<p>- XML<br />
- JSON<br />
- PHP Serialize</p>
<p>การเขียนเราก็อาจจะเขียนแค่</p>
<p>$params['appid'] = &#8216;xxxx&#8217;; //หามาใส่เอง<br />
$params['count'] = 30;<br />
$params['lang'] = &#8216;en&#8217;;<br />
$params['format'] = &#8216;xml&#8217;;</p>
<p>$query = http_build_query($params);</p>
<p>$urlRequest = sprintf(&#8216;http://boss.yahooapis.com/ysearch/web/v1/%s?&#8217;.$query, $search);</p>
<p>$xml = file_get_contents($urlRequest);</p>
<p>หลังจากได้ xml ก็เอา <a href="http://www.jquerytips.com/2008/07/06/how-to-use-php-simplexml/" target="_blank">SimpleXML</a> อ่าน ง่ายมากๆ</p>
<p>หรือถ้าเลือกรับ respond เป็น json ก็ยิ่งง่ายใช้คำสั่ง json_decode ถอดออกมาอ่านได้เลย </p>
<p>ปล. api ตัวนี้ของ yahoo unlimited นะครับ</p>
<blockquote><p><em>&#8220;Flexibility to reorder results. Full control over presentation. Ability to blend any data source with search results. Unlimited queries.&#8221;</em></p></blockquote>
<p>วันนี้จบแค่นี้ละกันเนอะ ^^</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jquerytips.com/2008/07/14/yahoo-search-boss/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>การทำ URL Shorten แบบเหยียบเมฆ ด้วย Tinyurl</title>
		<link>http://www.jquerytips.com/2008/06/23/shorten-url-tiny-php/</link>
		<comments>http://www.jquerytips.com/2008/06/23/shorten-url-tiny-php/#comments</comments>
		<pubDate>Sun, 22 Jun 2008 17:11:57 +0000</pubDate>
		<dc:creator>Tee++;</dc:creator>
				<category><![CDATA[Others]]></category>
		<category><![CDATA[API]]></category>

		<guid isPermaLink="false">http://www.jquerytips.com/2008/06/23/shorten-url-tiny-php/</guid>
		<description><![CDATA[วันนี้มาว่ากันด้วยบทความของ PHP กันสักหน่อยนะครับ กับการย่อ url ให้สั้นลง เพื่อสะดวกในการเก็บข้อมูล ที่มีพื้นที่จำกัด 
หลายๆ คนคงจะเคยทำ url shorten ง่ายๆ แบบนี้



http://www.jquerytips.co&#8230;.view.html



แต่วันนี้ผมมีวิธีเหนือชั้นกว่านั้นจะมาบอก นั่นคือการใช้ Service ของ tinyurl โดย url ที่ได้จะออกมาเป็น ลักษณะ




http://www.jquerytips.com/2008/06/22/markitup-jquery-plugin/



&#8211; จากด้านบนเป็นด้านล่าง &#8211;



http://tinyurl.com/6m8vkl



ดังนั้นเราจึงเอามาประยุกต์ได้เช่น user post ข้อความมา ยกตัวอย่างเช่น



&#60;?php


$content = &#34;สวัสดีครับวันนี้ผมไปดูหนังเรื่องนึงมาสนุกมากลองไปดู review ได้ที่ http://movie.sanook.com/news/news_14287.php กันนะครับ&#34;;


&#160;


function tinyurl&#40;$url&#41;


&#123;


&#160; $url = stripslashes&#40;$url&#41;;


&#160; if &#40;$url != &#34;&#34; &#38;&#38; substr&#40;$url, 0, 7&#41; == &#34;http://&#34;&#41;


&#160; &#123;


&#160; &#160; $tinyurl = @file_get_contents&#40;&#34;http://tinyurl.com/api-create.php?url=&#34;.$url&#41;;


&#160; &#160; $tinyurl [...]]]></description>
			<content:encoded><![CDATA[<p>วันนี้มาว่ากันด้วยบทความของ PHP กันสักหน่อยนะครับ กับการย่อ url ให้สั้นลง เพื่อสะดวกในการเก็บข้อมูล ที่มีพื้นที่จำกัด </p>
<p>หลายๆ คนคงจะเคยทำ url shorten ง่ายๆ แบบนี้</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">http://www.jquerytips.co&#8230;.view.html</div>
</li>
</ol>
</div>
<p>แต่วันนี้ผมมีวิธีเหนือชั้นกว่านั้นจะมาบอก นั่นคือการใช้ Service ของ <a href="http://www.tinyurl.com" target="_blank">tinyurl</a> โดย url ที่ได้จะออกมาเป็น ลักษณะ<br />
<span id="more-34"></span></p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">http://www.jquerytips.com/2008/06/22/markitup-jquery-plugin/
</div>
</li>
<li class="li1">
<div class="de1">&#8211; จากด้านบนเป็นด้านล่าง &#8211;
</div>
</li>
<li class="li1">
<div class="de1">http://tinyurl.com/6m8vkl</div>
</li>
</ol>
</div>
<p>ดังนั้นเราจึงเอามาประยุกต์ได้เช่น user post ข้อความมา ยกตัวอย่างเช่น</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">&lt;?php</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$content</span> = <span class="st0">&quot;สวัสดีครับวันนี้ผมไปดูหนังเรื่องนึงมาสนุกมากลองไปดู review ได้ที่ http://movie.sanook.com/news/news_14287.php กันนะครับ&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">function</span> tinyurl<span class="br0">&#40;</span><span class="re0">$url</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$url</span> = <a href="http://www.php.net/stripslashes"><span class="kw3">stripslashes</span></a><span class="br0">&#40;</span><span class="re0">$url</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$url</span> != <span class="st0">&quot;&quot;</span> &amp;&amp; <a href="http://www.php.net/substr"><span class="kw3">substr</span></a><span class="br0">&#40;</span><span class="re0">$url</span>, <span class="nu0">0</span>, <span class="nu0">7</span><span class="br0">&#41;</span> == <span class="st0">&quot;http://&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re0">$tinyurl</span> = @<a href="http://www.php.net/file_get_contents"><span class="kw3">file_get_contents</span></a><span class="br0">&#40;</span><span class="st0">&quot;http://tinyurl.com/api-create.php?url=&quot;</span>.<span class="re0">$url</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="re0">$tinyurl</span> = <span class="br0">&#40;</span>!<span class="re0">$tinyurl</span><span class="br0">&#41;</span> ? <span class="re0">$url</span> : <span class="re0">$tinyurl</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re0">$tinyurl</span> = <span class="re0">$url</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="kw1">return</span> <span class="st0">&quot;&lt;a href=&#8217;&quot;</span>.<span class="re0">$tinyurl</span>.<span class="st0">&quot;&#8217;&gt;&quot;</span>.<span class="re0">$tinyurl</span>.<span class="st0">&quot;&lt;/a&gt;&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <a href="http://www.php.net/preg_replace"><span class="kw3">preg_replace</span></a><span class="br0">&#40;</span><span class="st0">&#8216;#(http|HTTP|ftp)(s|S)?://([^<span class="es0">\s</span>&lt;&gt;<span class="es0">\.</span>]+)<span class="es0">\.</span>([^<span class="es0">\s</span>&lt;&gt;]+)#e&#8217;</span>, <span class="st0">&#8216;tinyurl(<span class="es0">\&#8217;</span>$1://$2$3.$4$5<span class="es0">\&#8217;</span>)&#8217;</span>, <span class="re0">$content</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2"><span class="co1">// Output</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/*สวัสดีครับวันนี้ผมไปดูหนังเรื่องนึงมาสนุกมากลองไปดู review ได้ที่ http://tinyurl.com/563ubl กันนะครับ*/</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">?&gt;</span></div>
</li>
</ol>
</div>
<p>จะเห็นได้ว่าวิธีการนี้เป็นการทำ url shorten รูปแบบใหม่ที่สะดวกดีไม่เลวทีเดียวนะครับ ^^</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jquerytips.com/2008/06/23/shorten-url-tiny-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Ajax Cross Domain ใครว่าทำไม่ได้</title>
		<link>http://www.jquerytips.com/2008/04/26/ajax-cross-domain/</link>
		<comments>http://www.jquerytips.com/2008/04/26/ajax-cross-domain/#comments</comments>
		<pubDate>Fri, 25 Apr 2008 18:56:32 +0000</pubDate>
		<dc:creator>Tee++;</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Jsonp]]></category>

		<guid isPermaLink="false">http://www.jquerytips.com/2008/04/26/ajax-cross-domain-%e0%b9%83%e0%b8%84%e0%b8%a3%e0%b8%a7%e0%b9%88%e0%b8%b2%e0%b8%97%e0%b8%b3%e0%b9%84%e0%b8%a1%e0%b9%88%e0%b9%84%e0%b8%94%e0%b9%89/</guid>
		<description><![CDATA[เรื่อง cross domain กับ ajax จริงๆแล้วในทางทฤษฎี มันควรจะทำได้ครับ แต่ทางปฎิบัติเราติดปัญหาเรื่อง Security  เลยไม่อนุญาติให้ทำกัน แต่ทีนี้ผมจะมาพูดถึง ajax cross domain อีกรูปแบบ ในกรณีที่อีก page ต่าง domain ยินยอมให้เข้าไป get ข้อมูล โดย register method ไว้ก่อน ซึ่งลักษณะนี้เรามักเรียกว่า Web Service หรือ API นั่นเอง 



var base_url = &#8216;http://www.jquerytips.com/debug/jsonp.php&#8217;;



&#160;



&#60;!&#8211; JavaScript &#8211;&#62;


$&#40;document&#41;.ready&#40;function&#40;&#41; &#123;


&#160; $&#40;&#8216;.doajax&#8217;&#41;.click&#40;function&#40;&#41; &#123;


&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; $.ajax&#40;&#123;


&#160; &#160; &#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>เรื่อง cross domain กับ ajax จริงๆแล้วในทางทฤษฎี มันควรจะทำได้ครับ แต่ทางปฎิบัติเราติดปัญหาเรื่อง Security  เลยไม่อนุญาติให้ทำกัน แต่ทีนี้ผมจะมาพูดถึง ajax cross domain อีกรูปแบบ ในกรณีที่อีก page ต่าง domain ยินยอมให้เข้าไป get ข้อมูล โดย register method ไว้ก่อน ซึ่งลักษณะนี้เรามักเรียกว่า <a href="http://en.wikipedia.org/wiki/Web_services" targe="_blank">Web Service</a> หรือ API นั่นเอง <span id="more-31"></span></p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> base_url = <span class="st0">&#8216;http://www.jquerytips.com/debug/jsonp.php&#8217;</span>;</div>
</li>
</ol>
</div>
<p>&nbsp;</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&lt;!&#8211; JavaScript &#8211;&gt;</div>
</li>
<li class="li1">
<div class="de1">$<span class="br0">&#40;</span>document<span class="br0">&#41;</span>.<span class="me1">ready</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; $<span class="br0">&#40;</span><span class="st0">&#8216;.doajax&#8217;</span><span class="br0">&#41;</span>.<span class="me1">click</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $.<span class="me1">ajax</span><span class="br0">&#40;</span><span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; url: base_url,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dataType: <span class="st0">&#8216;jsonp&#8217;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data: <span class="st0">&#8216;id=10&#8242;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jsonp: <span class="st0">&#8216;jsoncallback&#8217;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; success: <span class="kw2">function</span><span class="br0">&#40;</span>str<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $.<span class="me1">each</span><span class="br0">&#40;</span>str, <span class="kw2">function</span><span class="br0">&#40;</span>i, <span class="kw1">item</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span> i + <span class="st0">&#8216;=&#8217;</span> + <span class="kw1">item</span> <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&lt;!&#8211; JavaScript &#8211;&gt;</div>
</li>
</ol>
</div>
<p>&nbsp;</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&lt;a href=&quot;javascript:void(0);&quot; class=&quot;doajax&quot;&gt;Ajax Call&lt;/a&gt;</div>
</li>
</ol>
</div>
<p>ตามตัวอย่างโคดด้านบนจะเห็นได้ว่า dataType เราเป็น <a href="http://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/" target="_blank">jsonp</a> โดยที่เรามี callback ชื่อว่า jsoncallback ที่นี้เรามาดูโคดทางฝั่ง server ว่าจะคืนค่ามายังๆไง (ในที่นี้ผมใช้ php เป็น server side script)</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">&lt;?php</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">require_once</span><span class="br0">&#40;</span><span class="st0">&#8216;JSON/JSON.php&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$json</span> = <span class="kw2">new</span> Services_JSON<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2"><span class="re0">$arr</span><span class="br0">&#91;</span><span class="st0">&#8216;uri&#8217;</span><span class="br0">&#93;</span> = <span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st0">&#8216;REQUEST_URI&#8217;</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$arr</span><span class="br0">&#91;</span><span class="st0">&#8216;query&#8217;</span><span class="br0">&#93;</span> = <span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st0">&#8216;QUERY_STRING&#8217;</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="re0">$_GET</span><span class="br0">&#91;</span><span class="st0">&#8216;jsoncallback&#8217;</span><span class="br0">&#93;</span>.<span class="st0">&#8216;(&#8216;</span>.<span class="re0">$json</span>-&gt;<span class="me1">encode</span><span class="br0">&#40;</span><span class="re0">$arr</span><span class="br0">&#41;</span>.<span class="st0">&#8216;)&#8217;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">?&gt;</span></div>
</li>
</ol>
</div>
<p>สังเกตุว่าผมมีการ set ค่า $_GET['jsoncallback'] ก่อนที่จะ return data คืนให้นั่นคือตัวบอกครับ ว่าเราจะ allow callback ตัวนี้ เท่านี้เราก็จะได้ data ที่เป็น json กลับไปแล้วครับ ถึง 2 script นี้จะอยู่ต่าง domain กัน</p>
<p>จริงๆ แล้ว jQuery ในส่วนของ ajax request เรายังเขียนได้สั้นกว่านี้อีกนะครับ โดยเขียนแค่</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">$.<span class="me1">getJSON</span><span class="br0">&#40;</span>base_url + <span class="st0">&#8216;?jsoncallback=?&#8217;</span>, <span class="kw2">function</span><span class="br0">&#40;</span>obj<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $.<span class="me1">each</span><span class="br0">&#40;</span>obj, <span class="kw2">function</span><span class="br0">&#40;</span>i, <span class="kw1">item</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span> i + <span class="st0">&#8216;=&#8217;</span> + <span class="kw1">item</span> <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>ก็ยังทำงานได้เหมือนกันตามปกติ</p>
<p>ทีนี้เราลองมาคิดดูว่าการทำแบบนี้จะมีประโยชน์ยังไงบ้าง</p>
<p>1. ลด resource ของการทำงาน โดยเราไม่จำเป็นต้องใช้ server เดียวในการ return data<br />
2. สามารถทำ Web Service เพื่อให้ชาวบ้านมาใช้ได้ง่ายๆ</p>
<p>ตอนนี้คิดประโยชน์ได้แค่นี่ แหะๆ ^^</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jquerytips.com/2008/04/26/ajax-cross-domain/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
