php制作Unicode编码解码在线转换工具代码分享。
<?php
function unicode_encode($name)
{
$name = iconv('UTF-8', 'UCS-2', $name);
$len = strlen($name);
$str = '';
for ($i = 0; $i < $len - 1; $i = $i + 2)
{
$c = $name[$i];
$c2 = $name[$i + 1];
if (ord($c) > 0)
{ //两个字节的文字
$str .= '\u'.base_convert(o...
php使用strtotime和date函数判断日期是否有效代码分享
php使用strtotime和date函数进行检验判断日期是否有效代码分享,大家参考使用吧.
咋一想,判断日期是否有效应该是蛮简单的一个功能,但是细想起来还是有点麻烦的,因为既要检验格式,又要检验有效性。例如2013-02-29,虽然格式正确,但是日期无效;而2012-02-29格式正确,也有效。
一种方法可以使用正则,但是正则其实理解起来蛮麻烦的,而且使用正则在检验有效性方面也不太好。这里提供一个方法,主要是使...
php使用filter过滤器验证邮箱 ipv6地址 url验证
原来判断邮箱、url和ip地址格式是否符合都是用正则表达式,后来才知道在php中也可以使用内置的函数库filter来完成这些功能,下面分享给大家.
1、验证邮箱,代码如下:
$email = [email protected]';
$result = filter_var($email, FILTER_VALIDATE_EMAIL);
var_dump($result); //string(14) "[email protected]"
2、验证url地址,代码如下:
$url = "https://www.kexuesw520.com";
$result = filter_var($url, FILT...
zend framework文件上传功能实例代码
zend framework文件上传功能实例代码,php的版本5.3.8,zend framework的版本1.12,看下面的代码吧,有注释.
//实例化上传类
$upload = new Zend_File_Transfer();
//设置过滤器,大小限制为5M,格式为jpg,gif,png
$upload->addValidator('Size', false, 5 * 1024 * 1024);
$upload->addValidator('Extension', false, 'jpg,gif,png');
if (!$upload->isValid()) {
print '文件大小或格式不符...
php函数指定默认值方法的小例子
php函数指定默认值
在php编程中,为自定义函数设定默认值,当用户调用该函数时,如果不给参数指定值,参数会用默认值顶替。
例1,代码如下:
<html>
<head>
<title>php函数指定默认值-www.phpfensi.com</title>
</head>
<body>
<?php
function printMe($param = NULL)
{
print $param;
}
printMe("This is test");
printMe();
?>
</body>
</html&g...
Server.HTMLEncode让代码在页面里显示为源代码
今天因为程序里面要把写入数据库的html源代码以html源编码的形式显示在页面里面,而不要被浏览器解释成。。找了N久都不知道怎么做后来看了一下一个程序里面有修改模板的功能。。找了一个竟然是一个asp的方法^^记下来了
Server.HTMLEncode
HTMLEncode
一.HTMLEncode 方法对指定的字符串应用 HTML 编码。
语法
Server.HTMLEncode( string )
参数
string
指定要编码的字符串。
示例
脚本
代码如下:
<%= S...
PHP eval函数使用介绍
eval()函数中的eval是evaluate的简称,这个函数的作用就是把一段字符串当作PHP语句来执行,一般情况下不建议使用容易被黑客利用。
代码:
eval("echo'hello world';");
上边代码等同于下边的代码:
echo"hello world";
在浏览器中都输出:hello world
运用eval()要注意几点:
1.eval函数的参数的字符串末尾一定要有分号,在最后还要另加一个分号(这个分号是php限制)
2.注意单引号,双引号和反斜杠的运用...
php文件上传的例子及参数详解
这篇文章主要介绍了php文件上传的例子及参数,有需要的朋友可以参考一下
1.上传表单 upload.html
程序代码如下:
<form enctype="multipart/form-data" action="upload.php" method="post">
<input type="hidden" name="max_file_size" value="100000">
<input name="userfile" type="file">
<input type="submit" value="上传文件">
</form>
1.注意<form enctype="mu...
phpstrom使用xdebug配置方法
1 到 http://xdebug.org/download.php下载xdebug。注意找到自己对应的php版本。或者可以通过 http://xdebug.org/wizard.php页面,将phpinfo的信息复制进去,点最下面的分析。它会告诉你要下载哪个版本,然后如何配置。
2.打开php.ini添加以下语句
[XDEBUG]
zend_extension = "D:\Program Files (x86)\php5\ext\php_xdebug.dll"
xdebug.remote_enable=on
; 此地址为IDE所在IP
xdebug.remote_host=127.0.0....
解决file_get_contents无法请求https连接的方法
PHP.ini默认配置下,用file_get_contents读取https的链接,就会报如下错误,本文给出解决方法
错误: Warning: fopen() [function.fopen]: Unable to find the wrapper "https" - did you forget to enable it when you configured PHP?
解决方案有3:
1.windows下的PHP,只需要到php.ini中把extension=php_openssl.dll前面的;删掉,重启服务就可以了。
2.linux下的PHP,就必须安装openssl模块,安装好了以...