易栈网-膘叔

浏览模式: 标准 | 列表 | 图文
关于PHP正则的取反和逻辑思想的问题

关于PHP正则的取反和逻辑思想的问题

  众所周知,^这个符合在正则里非常有用,首先它代表了行首匹配,比如/^abc/,就代表了必须是abc开头,同样,它也是一个取反的标记。

  何为取反?就说刚才吧^abc是以abc开头,那么取反的意思就是不以abc三个字母的开头。

  正常情况下,这些都可以运用,不会有什么错误。

  再举个例子:我要判断字符串是否有特殊字符,怎么办?
  正常情况下,我会这样preg_match("/[_-~!@#$%^]+/",$string) ,当然特殊字符不止这么一些,只是举个简单的例子。
  如果我的$string = 'abcdefg--hijklmn',那么,我这样的匹配肯定是返回1的,因为有“-”被我匹配了。
  现在反过来讲,如果我不想匹配这些特殊字符怎么办?
  首先想到的就是取反,于是我preg_match("/[^-~!@#$%^]/",$string),再匹配一下,结果还是返回1。
  为啥呢?
  起初想半天就没想明白,为什么我明明取反了却匹配仍然成功呢?
  仔细思索了好久才明白,我取反之后,其实我的match的内容就变成了:与不是特殊字符匹配,那么我的string里面几乎全都不是特殊字符,当然就匹配成功了。
  所以,对于这种情况,还是先判断是否有特殊字符,然后再根据返回值再判断是否没有特殊字符吧。(有点象绕口令了)。

JS全选checkBox最佳方案

JS全选checkBox最佳方案

<input type="button" name="" value="不计算长度" onclick="a()">
<input type="button" name="" value="全选" onclick="b()">
<input type="button" value="缓存" onclick="c()">
<input type="checkbox" name="test[]" value="0"> 测试测试<br>
<script language="JavaScript">
<!--
var ca = new Array();
function a()
{
var m = document.getElementsByName('test[]');
for ( var i=0; i< m.length ; i++ ){
m[i].checked = !m[i].checked;
}
}

function b(){
var m = document.getElementsByName('test[]');
var l = m.length;
for ( var i=0; i< l; i++){
m[i].checked = !m[i].checked;
}
}

function c(){
if (ca.length == 0){
ca = cache();
}
cl = ca.length;
for ( var i=0; i< cl; i++){
ca[i].checked = ! ca[i].checked;
}
}

function cache(){
var m = document.getElementsByName('test[]');
var cache = new Array();
var l = m.length;
for ( var i=0; i< l; i++){
cache[i] = m[i];
}
return cache;
}
//-->
</script>

  黑黑,至于那个input type="checkbox"的,你们就尽量复制吧,尽量不要超过1W,否则。。别怪我没有提醒你,当然了,也不需要把浏览器关掉,跑到外面抽根烟再回来就行了。

  所以,我们要切实的记住,反正数组有长度的,坚决不能放在循环里面,而是先将这个长度取出来当成变量。PHP里也一样,循环数组的时候,先count数组的长度比较好。
当然了,我第三个采用了缓存,速度也是非常快的,比长度取好后再进行计算更快,因为连一次都不用取了(当然,除了第一次),全部扔给客户端了。

  上面的例子还是比较方便的,因为,checkbox的 name值都一样,如果不一样怎么办???
  只能这样:

<script language="JavaScript">
<!--
function check(){
var inputs = document.getElementsByTagName('input');
var inputsLen = inputs.length;
for (var i = 0; i < inputsLen ; i++ ){
if (inputs[i].type.toLowerCase() == 'checkbox') {
inputs[i].checked = !inputs[i].checked;
}
}
}
//-->
</script>
PHP常见错误(二)

PHP常见错误(二)

mySQL Result Source Errors
mySql 资源错误
Warning: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in…
You need to take a look at the $result variable used to define the loop. More than likely there is a syntax error on the reported line before the $result field, or the value of $result does not exist.
通常,在进行msyql_query后,你需要对取得的数据进行遍历,如果出现上面错误时,你得检查一下你的$result是否是一个resource,这种情况在SQL查询语句错误(但错误没有被抛出)的情况下,所以,发现此问题时,可以考虑打印出SQL,到PHPMYDMIN里执行一下看看是怎么回事。

Supplied argument is not a valid stream resource…
This is usually caused when your code is looking for a table or other resource in the database that does not exist.
这个问题的情况通常是你代码中指定的表或者资源不存在于该数据库

Sessions are not being created or maintained
Sessions 不能被创建或者被修改维护
This can apply to any of the scenarios below:
这可能会出现以下几种情况
(1) The program isn’t remembering your login 程序没有记录下你的登录状态
(2) Your shopping cart won’t hold items 你的购物车没有保持你的商品状态
(3) Your php script is redirecting like crazy 你的PHP代码跳转的太疯狂
(4) “Call undefined function session_start” error 你的服务器没有打开Session功能
(5) PHP isn’t processing pages called by something like index.php?page=home&id=7 你的PHP代码不能打开某个页面,比如index.php?page=home&id=7

Your site is most likely dependent on register_globals. You can enable them by putting this line in your .htaccess (or just enabling in your php.ini if you have access):
你的网站可能会依赖register_globals(全局变量)打开。你可以将下面这行加到你的.htaccess文件里(当然,如果你有权限更改PHP.ini,还是改php.ini更方便)
php_flag register_globals On

Stream Errors
文件流错误
Warning: failed to open stream…
Warning: main(/index.php): failed to open stream: No such file or directory in…

This is usually because either the specified file is missing, or a file declared in a require() or include() function is missing. The easiest way to fix this is by re-installing the PHP program from a freshly-uploaded copy, or restoring the original config.php and just changing the db information. The include path may also be incorrect, but either way your script is looking for a file that isn’t there, or it is looking in the wrong place.
这两个问题的出现,通常是文件没有找到或者文件不能被require和include。(上面的英文我觉得不太准,个人认为应该是:先检查一下文件是否确实存在,检查文件的路径,当然,还得看一下php.ini的include_path,如果这些都检查过了。那么尝试用绝对路径加载文件)

Warning: fopen(…): failed to open stream: Permission denied in…
This is a permissions and/or ownership issue. Try first setting the permissions to 777 just to see if the script will run. If so, you should narrow down the permissions to 775. If not, set the user/group to user:nobody.
文件没有权限被读取,如果你想要你的文件被读取,设置文件权限为775,如果该文件需要被执行,那么就设置成777。否则设置用户权限/组为:nobody

Warning: <…> is not a valid stream resource…
Warning: fread(): supplied argument is not a valid stream resource in…
This is an error seen when trying to use functions like fopen(), fread(), feof(), etc. and are usually caused by an invalid or unavailable resource that is being called in the line specified. For instance, if the fread() function is returning this error, it could be that the file it is trying to access does not have the correct permissions or does not exist.
这也是一个常见错误,当你使用fopen(), fread(), feof()等函数时,就可能会出现,错误原因一般是fopen()或者其他函数打开文件失败,但错误信息被屏蔽,如$fp=@fopen('file.txt');,在这种情况下,再使用fread()读取时,就会出现上面的出错信息。

Warning: Failed opening….
Warning: Failed opening ‘…’ for inclusion (include_path=’.:/usr/local/lib/php’) in Unknown on line 0
Make the sure that the file mentioned (and its holding directorie) has read + execute permissions, and that the path to the file is correct. If not, you’ll need to add the path into the PHP code: (or .htaccess)
请确认文件是否有读写权限并且路径是正确的。如果不是,你需要把路径加载到你的PHP代码或者.htaccess文件里

include(”/path/to/files”);
Blank PHP Pages

You go to a .php page, but it’s blank.
The scope of what can cause blank pages is very broad, but there are a few things to look at:
-Is error reporting turned off anywhere in the script or in the .htaccess? If so, turn it on to see what is happening (php_flag display_errors on), or add the lines at the top of this page into the script.
-Is the PHP script even generating any output (usually you can tell my finding the print function?
-Check the database connection, i.e, username, dbname, user added to db, etc.
-Try using the full <?PHP ?> tags, rather than the shorter versions <? ?>
当你转向到a.php的页面时,但是打开的却是空白页面,出现这种问题的原因有很多,这里只介绍一些让你尝试着解决一下:
1、错误报告是否关闭了?如果是,请打开错误报告,并且在你的这个文件里加上一些输出试试
2、是否PHP代码本身就是一个输出页面,试着寻找一下print之类的函数?
3、检查数据库连接,例如,用户名密码等
4、试着用完整的PHP标签:<?php?>,而尽量少用短标签<??>


Also, if the software is prebundled (like phpBB or Gallery), then the index or one of the include pages could be corrupted. Usually you can just replace the problem page with a working version from another installation.
有时,一些软件的测试版本中往往都会存在着一个错误或者BUG等,你可以试着将出错页用该程序的其他版本来替换掉。象(phpBB或者Ballery)


Max Execution Time Error
最大执行时间错误
You receive some variant of a “Max_execution_time” error when loading a page.
This is caused when a PHP script takes longer to execute than the server allows, but can be adjusted by adding a PHP directive to your .htaccess: (in seconds, 0 = unlimited) or modifying the value in php.ini.
php_value max_execution_time 0
打开页面时,显示 "Max_execution_time" 执行时间错误。
这应该是你的PHP代码在运行的时候,超过了服务器所允许的时候,但是,这是可以通过修改.htaccess或者php.ini来进行修改(0代表了不限制)
php_value max_execution_time 0


Open_basedir Errors

Warning: Unknown(): open_basedir restriction in effect.
This is a protective feature of Apache that restricts PHP from accessing files/folders outside the user’s home directory. Most of the time this is due to an incorrect include path in one or more of the config files (which are usually mentioned). Look for something like this:
/includes/somefile.php
/admin/files/anotherfile.php
The heading / tells the filesystem that these folders are on the server root, and thus prevents PHP from accessing them. You can usually fix this by changing the path to these files to be absolute to their location:
/home/username/public_html/includes/somefile.php
or
./includes/somefile.php
出现Open_basedir问题的时候,往往需要先检查,PHP_INI里面有没有设定open_basedir,如果PHP.ini里没有设定,还需要查看apache的http.conf的虚拟主机设定里,也否也进行了设置。如果设定了,还需要检查这些目录是否可读写,否则会出现受保护的错误。

周易:乾卦第一

周易:乾卦第一

乾:元亨、利贞。
初九:潜龙勿用。
九二:见龙在田,利见大人
九三:君子终日乾乾,夕惕若,厉,无咎。
九四:或跃在渊,无咎。
九五:飞龙在天,利见大人。
上九:亢龙有悔
用九:见群龙无首,吉。

Virtual Earth SDK

Virtual Earth SDK

Virtual Earth

The Virtual Earth map control software development kit (SDK) consists of a complete set of reference topics that cover the Virtual Earth map control application programming interface (API). The following versions of the SDK are available:

Virtual Earth also provides an Interactive SDK available at http://dev.live.com/virtualearth/sdk/. The Interactive SDK offers hands-on, task-based demonstrations of features available in the version 6.0 API release, complete with code samples and links back to the reference SDK.

Microsoft MapPoint Web Service is a hosted, programmable Web service that allows you to integrate high-quality maps, driving directions, distance calculations, proximity searches, and other location intelligence into your applications, business processes, and Web sites.

ThinkPHP两周年,同时有新的更新

新版介绍:

[ 1.0.2 ] 2008-2-21

  • Model类增加toArray方法
  • 修正因Log类的改动导致Trace错误信息无法正常显示的问题
  • 数据查询返回的数据集由ArrayObject对象改成数组
  • 修正Model类的create方法在定义字段映射的下面的bug
  • 修正虚拟模型下面create方法的bug
  • Model类的facade方法增加数据表字段的检测
  • 优化Image类的showAdvVerify方法
  • 修正标签库的compare标签
  • Trace配置文件由原来的_trace.php更名为trace.php
  • 项目调试配置文件由原来的_debug.php更名为debug.php
  • 项目配置文件由原来的_config.php更名为config.php
  • 路由定义文件由原来的_routes.php 更名为 routes.php
  • 静态定义文件由原来的_htmls.php 更名为 htmls.php
  • Model类的create方法无需type参数,自动判断新增和编辑模型数据
  • 增加第一次运行目录自动生成功能(只需要定义入口文件)
  • 默认项目编译缓存目录为Temp目录
小孩的彩照

小孩的彩照

地址在:http://www.neatcn.com/attachments/mybaby.avi

古人云,三十而立,而立之年老婆给我带来了一个小孩。或许能够让我不安份的心能够安份一点。
虽然不是很喜欢小孩,因为担心长大后象我一样,不好好的读书不好好的学习,不会做人什么的,但是既然他要来了,那么总是一条新的生命,希望ta能健康快乐的成长


JpGraph中文乱码完美解决方案[转]

JpGraph中文乱码完美解决方案[转]

很多人使用JpGraph会出现乱码问题,但是网上有好多并无效果的解决方式,经过反复试验及在网上看了其它人的经验,总结出在2.3版下最终较完美解决方案
1、把simsun.ttc字体拷到服务器/usr/X11R6/lib/X11/fonts/truetype下,当然这个目录可以自定义
2、不需要更改$aFF === FF_SIMSUN或$aFF === FF_CHINESE ,直接用以下代码即可
$title = "JpGraph中文测试";
$title = iconv("UTF-8", "gb2312", $title);
$graph->title->Set($title);
就可以完美的解决中文问题了
3、还有一个问题,就是右上方的中文显示问题,就是SetLegend函数,解决方式如下
打开jpgraph.php文件,找到
private $font_family=FF_FONT1,$font_style=FS_NORMAL,$font_size=12;
用
private $font_family=FF_SIMSUN,$font_style=FS_NORMAL,$font_size=8;
替换就OK了^_^