博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
tinyurl_使用TinyURL,MooTools和PHP创建Tiny URL
阅读量:2512 次
发布时间:2019-05-11

本文共 2359 字,大约阅读时间需要 7 分钟。

tinyurl

Since we've already figured out how to , we may as well create a small AJAX-enabled tiny URL creator. Using MooTools to do so is almost too easy.

由于我们已经找到了如何 ,因此我们也可以创建一个支持AJAX的小型URL创建器。 使用MooTools这样做太容易了。

XHTML(窗体) (The XHTML (Form))

URL:

We need an input box where the user will enter their a URL, a button to trigger the process, and a placeholder to put the new, tiny URL.

我们需要一个输入框,用户将在其中输入其URL,一个按钮以触发该过程以及一个占位符以放置新的微小URL。

PHP (The PHP)

if(isset($_GET['url'])) {	die(get_tiny_url(urldecode($_GET['url'])));}//gets the data from a URL  function get_tiny_url($url)  {  	$ch = curl_init();  	$timeout = 5;  	curl_setopt($ch,CURLOPT_URL,'http://tinyurl.com/api-create.php?url='.$url);  	curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);  	curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);  	$data = curl_exec($ch);  	curl_close($ch);  	return $data;  }

This PHP snippet grabs and returns the tiny URL from TinyURL.

该PHP代码段从TinyURL抓取并返回微小的URL。

MooTools JavaScript (The MooTools JavaScript)

window.addEvent('domready',function() {	var TinyURL = new Class({		//implements		Implements: [Options],		//options		options: {			checkURL: ''		},		//initialization		initialize: function(options) {			//set options			this.setOptions(options);		},		//a method that does whatever you want		createURL: function(url,complete) {			var req = new Request({				url: this.options.checkURL + '?url=' + url,				method: 'get',				async: false,				onComplete: function(response) { complete(response); }			}).send();		}	});			// usage //	var new_tiny_url = new TinyURL({		checkURL: 'grab-tiny-url.php'	});		$('geturl').addEvent('click',function() {		if($('url').value) {			var newu = new_tiny_url.createURL($('url').value,function(resp) {				$('newurl').set('html','The TinyURL is .  Go ahead, try it!').setStyle('color','green');			});		}	});});

Just a tiny MooTools class and basic usage. The only parameter, "checkURL," is the URL to the PHP snippet above -- NOT the long URL we want to shrink. The real action happens when the createURL() method is invoked. You pass the method a URL to shorten and an "onComplete" function that takes action when the URL has been received.

只是一个很小的MooTools类和基本用法。 唯一的参数“ checkURL”是上述PHP代码段的URL,而不是我们要缩小的长URL。 真正的动作发生在调用createURL()方法时。 您为该方法传递了一个要缩短的URL和一个“ onComplete”函数,该函数在收到URL时即会起作用。

TinyURL is a great service!

TinyURL是一项很棒的服务!

翻译自:

tinyurl

转载地址:http://ulpwd.baihongyu.com/

你可能感兴趣的文章
《社交红利》读书总结--如何从微信微博QQ空间等社交网络带走海量用户、流量与收入...
查看>>
JDK工具(一)–Java编译器javac
查看>>
深入.NET框架与面向对象的回顾
查看>>
改变label中的某字体颜色
查看>>
[转]SQL SERVER 的排序规则
查看>>
C语言函数的可变参数列表
查看>>
七牛云存储之应用视频上传系统开心得
查看>>
struts2日期类型转换
查看>>
Spark2-数据探索
查看>>
大数据初入门
查看>>
Java学习笔记-类型初始化
查看>>
鱼那么信任水,水却煮了鱼
查看>>
Http和Socket连接区别
查看>>
Arrays基本使用
查看>>
Angular2,Springboot,Zuul,Shiro跨域CORS请求踩坑实录
查看>>
C语言中操作符的优先级大全
查看>>
pgpool-II - 介绍
查看>>
[转载+原创]Emgu CV on C# (四) —— Emgu CV on 全局固定阈值二值化
查看>>
#leetcode刷题之路29- 两数相除
查看>>
Alpha冲刺(10/10)——2019.5.2
查看>>