≡
  • 网络编程
  • 数据库
  • CMS技巧
  • 软件编程
  • PHP笔记
  • JavaScript
  • MySQL
位置:首页 > 网络编程 > PHP笔记

php 的IRC API库的简单示例

人气:542 时间:2018-09-21

这篇文章主要为大家详细介绍了php 的IRC API库的简单示例,具有一定的参考价值,可以用来参考一下。

对一个php编写的IRC API库感兴趣的小伙伴,下面一起跟随四海网的小编两巴掌来看看吧!

<?php
/**
  * 一个php编写的IRC API库
  *
  * Mark的IRC API库
  *
  * 格式化发送到IRC网络的数据。 这个库无法处理
  * 实际连接到IRC服务器或解析IRC服务器输出。
  *
  * raw_send方法可用于以XML格式将数据发送到IRC
  * 要么不标准,要么尚未实施。 我知道还有很多
  * 实施,我计划随着时间的推移这样做。
  *
  * @param 
  * @author 五一二笔记网: www.q1010.com
  *
 **/
class IRC
{
	/**
	 * Library version
	 * 
	 * @access protected
	 * @var    string
	 */
	protected $_version = '1.0.0';
	/**
	 * Connection socket
	 * 
	 * @access protected
	 * @var    object
	 */
	protected $_socket;
	/**
	 * Constructor
	 * 
	 * configures the class for use
	 * 
	 * @access public
	 * @param  object
	 * @return void
	 */
	public function __construct($socket)
	{
		$this->_socket = $socket;
	}
	/**
	 * version
	 * 
	 * Reports the libraries version
	 * 
	 * @access public
	 * @return string
	 */
	public function version()
	{
		return $this->_version;
	}
	/**
	 * say
	 * 
	 * send a message to the target
	 * 
	 * @access public
	 * @param  string  $target
	 * @param  string  $message
	 * @return void
	 */
	public function say($target, $message)
	{
		$data = "PRIVMSG {$target} :{$message}";
		$this->raw_send($data);
	}
	/**
	 * emote
	 * 
	 * send an emote to the target ( equiv to IRC client /me does something )
	 * 
	 * @access public
	 * @param  string $target
	 * @param  string $message
	 * @return void
	 */
	public function emote($target, $message)
	{
		$data = chr(1)."ACTION {$message}".chr(1);
		$this->say($target, $data);
	}
	/**
	 * ctcp
	 * 
	 * send a ctcp to the target
	 * 
	 * @access public
	 * @param  string $target
	 * @param  string $message
	 * @return void
	 */
	public function ctcp($target, $message)
	{
		$data = chr(1).$message.chr(1);
		$this->say($target, $data);
	}
	/**
	 * notice
	 * 
	 * send a notice to the target
	 * 
	 * @access public
	 * @param  string  $target
	 * @param  string  $message
	 * @return void
	 */
	public function notice($target, $message)
	{
		$data = "NOTICE {$target} :{$message}";
		$this->raw_send($data);
	}
	/**
	 * set_nick
	 * 
	 * change user nick name
	 * 
	 * @access public
	 * @param  string
	 * @return void
	 */
	public function set_nick($nick)
	{
		$data = "NICK {$nick}";
		$this->raw_send($data);
	}
	/**
	 * set_user
	 * 
	 * prepare user ident string
	 * 
	 * @access public
	 * @param  string
	 * @return void
	 */
	public function set_user($nick)
	{
		$data = "USER $nick $nick $nick $nick :$nick";
		$this->raw_send($data);
	}
	/**
	 * send_pass
	 * 
	 * Identify with nickserv
	 * 
	 * @access public
	 * @param  string
	 * @return void
	 */
	public function send_pass($password)
	{
		$this->say('nickserv', "IDENTIFY {$password}");
	}
	/**
	 * disconnect
	 * 
	 * Terminates IRC connection. Does not terminate reset process in the case
	 * you have implemented a reconnect function
	 * 
	 * @access public
	 * @param  string|null
	 * @return void
	 */
	public function disconnect($message = NULL)
	{
		$data = ($message !== NULL) ? "QUIT :{$message}" : "QUIT";
		$this->raw_send($data);
	}
	/**
	 * enter_channel
	 * 
	 * enter an IRC channel
	 * 
	 * @access public
	 * @param  string
	 * @return void
	 */
	public function enter_channel($channel)
	{
		$data = ($channel[0] == '#') ? "JOIN {$channel}" : "JOIN #{$channel}";
		$this->raw_send($data);
	}
	/**
	 * leave_channel
	 * 
	 * leaves an IRC channel
	 * 
	 * @access public
	 * @param  string
	 * @return void
	 */
	public function leave_channel($channel)
	{
		$data = ($channel[0] == '#') ? "PART {$channel}" : "PART #{$channel}";
		$this->raw_send($data);
	}
	/**
	 * raw_send
	 * 
	 * Sends raw commands to the IRC server. I left it a public function for
	 * hackability reasons. Makes it easier to add custom commands for
	 * non-standard servers, or to test new features without having to edit
	 * the class directly every time. Of course you could always just extend
	 * the class.
	 * 
	 * @access public
	 * @return void
	 */
	public function raw_send($data)
	{
		fwrite($this->_socket, $data."\n");
	}
}
/***   来自四海网(www.q1010.com)   ***/

本文来自:http://www.q1010.com/173/708-0.html

注:关于php 的IRC API库的简单示例的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。

关键词:IRC

您可能感兴趣的文章

上一篇:php 年龄计算函数用法示例
下一篇:php 删除指定目录,并递归删除子目录的简单示例
热门文章
  • PHP 写入WRITE编码为UTF8的文件示例
  • PHP 中文字符串截取函数示例:支持gb2312,gbk,big
  • PHP 简单留言板的制作示例
  • 解决Fatal error: Call to undefined function mb_convert_encoding() in错误问题
  • PHP语言基础(标记、注释、变量、数组、常量、函数)示例
  • php 生成迅雷链接的简单示例
  • php 获取短网址的实现方法
  • PHP 通用分页类的简单示例
  • PHP 使用文件方式导入导出整个MYSQL数据库的实现方法
  • php 获取MYSQL错误的简单示例
  • 最新文章
    • 解决PHP使用redis实现统计缓存MySQL压力的问题
    • php 简单的上传进度条的简单示例
    • php 给html中引用的js和css路径打上版本号的实现方法
    • php 实现计算年龄精准到年月日的实例
    • php+ajax无刷新分页的简单示例
    • 解决php+ajax无刷新上传图片的问题
    • 解决PHP生成HTML静态页面的问题
    • 解决PHP使用uniqid函数生成唯一ID的问题
    • 解决PHP防刷票的一些问题
    • 微信access_token的获取开发的实现方法

四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。