文章列表
 
您正在查看 "计算机网络" 分类下的文章

2008-07-15 17:05
希望对初学C语言语言的同志有所帮助;

当然,应用这个口诀的前提是你必须认识所有的C语言的运算符。

   优先决
括号成员第一;        //括号运算符[]() 成员运算符.   ->
全体单目第二;        //所有的单目运算符比如++ -- +(正) -(负) 指针运算*&
乘除余三,加减四; //这个"余"是指取余运算即%
移位五,关系六; //移位运算符:<< >> ,关系:> < >= <= 等
等于(与)不等排第七; //即== !=
位与异或和位或; //这几个都是位运算: 位与(&)异或(^)位或(|)    
"三分天下"八九十;  
逻辑或跟与;          //逻辑运算符:|| 和 &&
十二和十一;          //注意顺序:优先级(||)   底于 优先级(&&)
条件高于赋值,    //三目运算符优先级排到 13 位只比赋值运算符和","高//需要注意的是赋值运算符很多!
逗号运算级最低! //逗号运算符优先级最低

由于C语言的运算符优先级与C++的不完全一样(主要是增加了几个运算符),所以这个口诀不能完全实用于C++.但是应该能够兼容,大家可以比较一下他们的区别应该就能够很快掌握C++的优先级的!
 
2008-04-02 1:57
<?php
/* A sample service:
 *
 * php sample.php install
 * net start dummyphp
 * net stop dummyphp
 * php sample.php uninstall
 */

if ($argv[1] == 'install') {
 $x = win32_create_service(array(
  'service' => 'dummyphp',
  'display' => 'sample dummy PHP service',
  'params' => __FILE__ . ' run',
 ));
 debug_zval_dump($x);
 exit;
} else if ($argv[1] == 'uninstall') {
 $x = win32_delete_service('dummyphp');
 debug_zval_dump($x);
 exit;
} else if ($argv[1] != 'run') {
 die("bogus args");
}

$x = win32_start_service_ctrl_dispatcher('dummyphp');

while (WIN32_SERVICE_CONTROL_STOP != win32_get_last_control_message()) {
 usleep(250000);
}

?>
 
2008-04-02 1:37

原文:http://netevil.org/blog/2005/sep/running-php-as-a-service-on-win32

[Update: I wrote some docs for the php manual]

So, you've written some kind of super-duper daemon process in PHP, perhaps using the event extension and stream_socket_server(). On Unix, it's quite a simple matter to have it run from init (or maybe inetd) when your machine starts... but doing the same on windows isn't possible without some hacks. Until now.

Last night I put together 2 new extensions for windows; the first of these is called win32service and it allows you run your PHP scripts from the "Service Control Manager" (SCM). The SCM is roughly analagous to the init process on unix, in that it runs tasks on startup and monitors their status, optionally restarting them if something goes awry.

I've included a sample service script that demonstrates minimal usage. Before you can run a script as a service, you need to register it with the SCM; in the sample, you do this by running it with the "install" argument on the command line. Once installed, you can use either the services MMC snap-in (run services.msc, or look for it under "Administrative Tools") or the good old fashined "net" command to launch or stop the service. I prefer the latter:

net start dummyphp

The output from the command should indicate the service started correctly; use the task manager to verify this--you should see a php.exe process running as SYSTEM. This dummy service does nothing much; just sleeps and waits for the SCM to tell it to stop; lets do that now:

net stop dummyphp

Again, the output from that command should indicate that the service stopped, and your task manager should no longer show php.exe running as SYSTEM. Now that we've proved that it works, we should remove the same from the SCM; running the script with the "uninstall" argument will do this.

It's all pretty straight-forward; the most complicated part is the win32_create_service() function; the first argument is an array that describes the service; the following keys are supported:

  • service - the short name of the service. You can't have two services with the same name.
  • display - the display name of the service.
  • user - the account name under which to run the service. If omitted, runs as the local system account
  • password - the password to match the "user" setting.
  • path - full path to the binary to run. If omitted, the full path to the currently running process will be used (typically php.exe)
  • params - command line parameters to pass to the binary. You'll probably want to specify the full path to a PHP script, plus some parameter to indicate that the script should run as a service.

(there are some more keys but they're not fully supported yet)

When it comes to actually running your service, you should call win32_start_service_ctrl_dispatcher() and pass in the name of the service. This function checks-in with the SCM; it is especially important that you do this as soon as possible in your script, as the SCM blocks while it waits for you to check-in--you can cause system-wide issues if you take too long.

While your service is running, you should periodically check to see if the SCM has requested that you stop. One way to do this is to wrap the main body of your service code in a while loop like this:

<?php
   while (WIN32_SERVICE_CONTROL_STOP != win32_get_last_control_message()) {
      // do stuff here, but try not to take more than a few seconds
   }
?>

If you already have an event loop, you can fold the above into your application. If you're using the event extension, you can schedule a recurrent timed event to check for the stop condition.

And that's pretty much all there is to say for now. I strongly recommend that you look through the MSDN documentation on services; it's very valuable background information.

The binaries for PHP 5 should show up under http://snaps.php.net/win32/PECL_5_0/ in the next couple of hours.

Enjoy :)

 
2008-04-02 0:37

UTF8
[\x01-\x7f]|[\xc0-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}

UTF16
[\x00-\xd7][\xe0-\xff]|[\xd8-\xdf][\x00-\xff]{2}

JIS
[\x20-\x7e]|[\x21-\x5f]|[\x21-\x7e]{2}

SJIS
[\x20-\x7e]|[\xa1-\xdf]|([\x81-\x9f]|[\xe0-\xef])([\x40-\x7e]|[\x80-\xfc])

SJIS全角空格
(?:\x81\x81)

SJIS全角数字
(?:\x82[\x4f-\x58])

SJIS全角大写英文
(?:\x82[\x60-\x79])

SJIS全角小写英文
(?:\x82[\x81-\x9a])

SJIS全角平假名
(?:\x82[\x9f-\xf1])

SJIS全角平假名扩展
(?:\x82[\x9f-\xf1]|\x81[\x4a\x4b\x54\x55])

SJIS全角片假名
(?:\x83[\x40-\x96])

SJIS全角片假名扩展
(?:\x83[\x40-\x96]|\x81[\x45\x5b\x52\x53])

EUC_JP
[\x20-\x7e]|\x81[\xa1-\xdf]|[\xa1-\xfe][\xa1-\xfe]|\x8f[\xa1-\xfe]{2}

EUC_JP标点符号及特殊字符
[\xa1-\xa2][\xa0-\xfe]

EUC_JP全角数字
\xa3[\xb0-\xb9]

EUC_JP全角大写英文
\xa3[\xc1-\xda]

EUC_JP全角小写英文
\xa3[\xe1-\xfa]

EUC_JP全角平假名
\xa4[\xa1-\xf3]

EUC_JP全角片假名
\xa3[\xb0-\xb9]|\xa3[\xc1-\xda]|\xa5[\xa1-\xf6][\xa3][\xb0-\xfa]|[\xa1][\xbc-\xbe]|[\xa1][\xdd]

EUC_JP全角汉字
[\xb0-\xcf][\xa0-\xd3]|[\xd0-\xf4][\xa0-\xfe]|[\xB0-\xF3][\xA1-\xFE]|[\xF4][\xA1-\xA6]|[\xA4][\xA1-\xF3]|[\xA5][\xA1-\xF6]|[\xA1][\xBC-\xBE]

EUC_JP全角空格
(?:\xa1\xa1)

EUC半角片假名
(?:\x8e[\xa6-\xdf])

日文半角空格
\x20

Big5
[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|[\xa1-\xfe])

GBK
[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]

GB2312汉字
[\xb0-\xf7][\xa0-\xfe]

GB2312半角标点符号及特殊符号
\xa1[\xa2-\xfe]

GB2312罗马数组及项目序号
\xa2([\xa1-\xaa]|[\xb1-\xbf]|[\xc0-\xdf]|[\xe0-\xe2]|[\xe5-\xee]|[\xf1-\xfc])

GB2312全角标点及全角字母
\xa3[\xa1-\xfe]

GB2312日文平假名
\xa4[\xa1-\xf3]

GB2312日文片假名
\xa5[\xa1-\xf6]

GB18030
[\x00-\x7f]|[\x81-\xfe][\x40-\xfe]|[\x81-\xfe][\x30-\x39][\x81-\xfe][\x30-\x39]

public class CnCharsetChecker {
    /* Support for Chinese(GB2312) characters */
    // #define isgb2312head(c) (0xa1<=(uchar)(c) && (uchar)(c)<=0xf7)
    // #define isgb2312tail(c) (0xa1<=(uchar)(c) && (uchar)(c)<=0xfe)
    public static boolean isGB2312(byte head, byte tail) {
        int iHead = head & 0xff;
        int iTail = tail & 0xff;
        return ((iHead>=0xa1 && iHead<=0xf7 &&
                 iTail>=0xa1 && iTail<=0xfe) ? true : false);
    }
    /* Support for Chinese(GBK) characters */
    // #define isgbkhead(c) (0x81<=(uchar)(c) && (uchar)(c)<=0xfe)
    // #define isgbktail(c) ((0x40<=(uchar)(c) && (uchar)(c)<=0x7e)
    //                      || (0x80<=(uchar)(c) && (uchar)(c)<=0xfe))
    public static boolean isGBK(byte head, byte tail) {
        int iHead = head & 0xff;
        int iTail = tail & 0xff;
        return ((iHead>=0x81 && iHead<=0xfe &&
                 (iTail>=0x40 && iTail<=0x7e ||
                  iTail>=0x80 && iTail<=0xfe)) ? true : false);
    }
    /* Support for Chinese(BIG5) characters */
    // #define isbig5head(c) (0xa1<=(uchar)(c) && (uchar)(c)<=0xf9)
    // #define isbig5tail(c) ((0x40<=(uchar)(c) && (uchar)(c)<=0x7e)
    //                       || (0xa1<=(uchar)(c) && (uchar)(c)<=0xfe))
    public static boolean isBIG5(byte head, byte tail) {
        int iHead = head & 0xff;
        int iTail = tail & 0xff;
        return ((iHead>=0xa1 && iHead<=0xf9 &&
                 (iTail>=0x40 && iTail<=0x7e ||
                  iTail>=0xa1 && iTail<=0xfe)) ? true : false);
    }

    public static void main(String[] args) {
        String sGB = "爱";
        String sGBK = "愛";
        String sBIG5 = "稲";
        byte[] sChars = null;
        sChars = sGB.getBytes();
        System.out.println(sGB + " is " +
            CnCharsetChecker.isGB2312(sChars[0],sChars[1]) + " for GB2312;" +
            CnCharsetChecker.isGBK(sChars[0],sChars[1]) + " for GBK," +
            CnCharsetChecker.isBIG5(sChars[0],sChars[1]) + " for BIG5");
        sChars = sGBK.getBytes();
        System.out.println(sGBK + " is " +
            CnCharsetChecker.isGB2312(sChars[0],sChars[1]) + " for GB2312;" +
            CnCharsetChecker.isGBK(sChars[0],sChars[1]) + " for GBK," +
            CnCharsetChecker.isBIG5(sChars[0],sChars[1]) + " for BIG5");
        sChars = sBIG5.getBytes();
        System.out.println(sBIG5 + " is " +
            CnCharsetChecker.isGB2312(sChars[0],sChars[1]) + " for GB2312;" +
            CnCharsetChecker.isGBK(sChars[0],sChars[1]) + " for GBK," +
            CnCharsetChecker.isBIG5(sChars[0],sChars[1]) + " for BIG5");
    }
}

 
2008-03-28 3:52
今天在翻译一套英文程序时看到Markup这个词,一时不知道翻译成什么好,在网上也找不到答案,有说是“标记”,可这个词在计算机里是什么意思,思来想去,我还是把它译成了“标签”
 
2008-01-15 13:39
错误MySQL 返回:
#1251 - Client does not support authentication protocol requested by server; consider upgrading MySQL client

出现这种问题也只有在MYSQL4.1.x以上版本,用4.0.x就没问题了

原因是因为你使用的mysql服务器版本中使用了新的密码验证机制,这需要客户端的版本要在4.0以上,原来的密码函数被改为old_password ();,这样使用password()生成的密码在旧的版本上的客户端就不好使了,而PHP中的MYSQL客户端都是3.23的(当然,mysqli的扩展除外),问题就在这了。

目前已知解决方法:

1、进入命令行下,转到MYSQL目录的BIN目录下,进入MYSQL命令行模式:
         例:d:\mysql\bin>mysql -uroot -p123         (用户root,密码123)
2、输入命令:
         mysql>set password for 'root'@'localhost'=old_password('123');         (注意冒号不能少)
3、退入MYSQL命令行:
         mysql>\q

A.2.3. 客户端不支持鉴定协议

MySQL 5.1采用了基于密码混编算法的鉴定协议,它与早期客户端(4.1之前)使用的协议不兼容。如果你将服务器升级到4.1之上,用早期的客户端进行连接可能失败,并给出下述消息:

shell> mysql
客户端不支持服务器请求的鉴定协议:请考虑升级MySQL客户端。

要想解决该问题,应使用下述方法之一:

·         升级所有的客户端程序,以使用4.1.1或更新的客户端库。

·         4.1版之前的客户端连接到服务器时,请使用仍具有4.1版之前风格密码的账户。

·         对于需要使用4.1版之前的客户端的每位用户,将密码恢复为4.1版之前的风格。可以使用SET PASSWORD语句和OLD_PASSWORD()函数完成该任务:

·                mysql> SET PASSWORD FOR
·                         -> 'some_user'@'some_host' = OLD_PASSWORD('newpwd');

也可以使用UPDATEFLUSH PRIVILEGES

mysql> UPDATE mysql.user SET Password = OLD_PASSWORD('newpwd')
         -> WHERE Host = 'some_host' AND User = 'some_user';
mysql> FLUSH PRIVILEGES;

用你打算使用的密码替换前例中的“newpwd”。MySQL不能告诉你原来的密码是什么,因此,你需要选择新的密码。

·         通知服务器使用旧的密码混编算法:

1.    使用“--old-passwords”选项启动mysqld

2.    对于已将密码更新为较长4.1格式的每个账户,为其指定具有旧格式的密码。可以使用下述查询确定这些账户:

3.                 mysql> SELECT Host, User, Password FROM mysql.user
4.                          -> WHERE LENGTH(Password) > 16;

对于查询显示的每个账户记录,请使用HostUser值,并使用OLD_PASSWORD()函数以及SET PASSWORDUPDATE之一指定密码,如前面所介绍的那样。

注释:在早期的PHP版本中,mysql扩展不支持MySQL 4.1.1和更高版中的鉴定协议。无论使用的PHP版本是什么,它均是正确的。如果你打算与MySQL 4.1或更高版本一起使用mysql扩展,需要使用前面介绍的选项之一,配置MySQL,以便与较早的客户端一起使用。mysqli扩展(支持改进的MySQL”,在PHP 5中增加)与MySQL 4.1和更高版本中使用的改进的密码混编算法兼容,不需要对MySQL进行特殊配置就能使用该MySQL客户端库。关于mysqli扩展的更多信息,请参见http://php.net/mysqli

  首先说明一下,下面描述仅限于Win系统 其它系统我没试过,Mysql 自从4.1.1以后修改了用户密码的格式, 从16位增加到了41位, 采用了一种新的验证方法,但4.1以前的客户端协议不支持这种方法,所以造成了不能登临的后果.即使密码正确了不能正常登录,提示如下:
  #1250 - Client does not support authentication protocol requested by server; consider upgrading MySQL client
  
  在窗口中执行:
  C:\mysql\bin>mysql -uroot
  Welcome to the MySQL monitor. Commands end with ; or \g.
  Your MySQL connection id is 1 to server version: 5.0.0-alpha-nt
  
  Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
  
  mysql> select password('aa');
  +-------------------------------------------+
  | password('aa')              |
  +-------------------------------------------+
  | *DEE59C300700AF9B586F9F2A702231C0AC373A13 |
  +-------------------------------------------+
  1 row in set (0.00 sec)
  
  mysql>
  从上可以看出password的结果返回了一个以'*'号开头的41位字符串,而以前是16位的.
  
  Mysql官方网站给出了二种解决方法
  
  1,使用新的客户端api,
  2,强制服务器使用旧的密码方案
  
  我首先尝试了第一种方法,从mysql5.0中拷贝libmysql.dll到php 的扩展目录中,替代了php本身附带的libmysql.dll, 但结果令人失望. Php提示装入php_mysql.dll失败:PHP Warning: PHP Startup: Unable to load dynamic library 'c:/php5/ext/php_mysql.dll' - 找不到指定的程序。后来发现新版的dll中缺少了mysql_drop_db() 这一函数 :( 只有等php或mysql出更新的dll了.
  
  第一种方法行不通,只有试试第二种方法,mysql的官方FAQ中说,需要加上-old-password这一参数,我首先尝试 在命令行下起动mysql,
  c:\mysql\bin>mysqld-nt -old-password
  
  在另一窗口中 运行
  C:\mysql\bin>mysql -uroot
  Welcome to the MySQL monitor. Commands end with ; or \g.
  Your MySQL connection id is 540 to server version: 5.0.0-alpha-nt
  
  Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
  
  mysql> select password('mypassword');
  +------------------------+
  | password('mypassword') |
  +------------------------+
  | 162eebfb6477e5d3    |
  +------------------------+
  1 row in set (0.55 sec)
  
  mysql>
  
  可以看出password的结果又变成16位的了,可喜的变化
  
  我在c:\windows\my.ini (xp,98,中如此,2000中应在c:\wint\下)中的"mysqld"段中加入"set-variable=old-passwords"
  
  例:
  [mysqld]
  basedir=C:/mysql
  set-variable=old-passwords
  datadir=C:/mysql/data
  [WinMySQLadmin]
  Server=C:/mysql/bin/mysqld-nt.exe
  user=root
  password=mypassword
  
  然后在服务管理器中起动mysql
  
  Very Good, 一切正常,
  
  后来我又发现,只要在mysql.user表中把password的字段长度改成16系统就自动切换到了oldpassword方式,改成改回41后 又自动换到了新的验证方式.
  在这里提醒一下,更改password方式后,要重新设制一下密码并刷新一下权限(或重起mysql)


转自:http://hi.baidu.com/%CB%CE%CF%FE%C1%C1/blog/item/cb1897cacfd21287c9176847.html

 
2007-12-25 4:06
 
2007-12-25 4:05
 
2007-12-25 4:04
Google地图(Google Map)jQuery Plugin googlemaps.
jMaps jQuery Maps Framework.
jQmaps.
jQuery & Google Maps.
jQuery Maps Interface forr Google and Yahoo maps.
jQuery J Maps - by Tane Piper.
游戏(Games)Tetris with jQuery.
jQuery Chess.
Mad Libs Word Game.
jQuery Puzzle.
jQuery Solar System (not a game but awesome jQuery Stuff).
表格等(Tables, Grids etc.)UI/Tablesorter.
jQuery ingrid.
jQuery Grid Plugin.
Table Filter - awesome!.
TableEditor.
jQuery Tree Tables.
Expandable “Detail” Table Rows.
Sortable Table ColdFusion Costum Tag with jQuery UI.
jQuery Bubble.
TableSorter.
Scrollable HTML Table.
jQuery column Manager Plugin.
jQuery tableHover Plugin.
jQuery columnHover Plugin.
jQuery Grid.
TableSorter plugin for jQuery.
tEditable - in place table editing for jQuery.
jQuery charToTable Plugin.
jQuery Grid Column Sizing.
jQuery Grid Row Sizing.
统计图(Charts, Presentation etc.)jQuery Wizard Plugin .
jQuery Chart Plugin.
Bar Chart.
边框、圆角、背景(Border, Corners, Background)jQuery Corner.
jQuery Curvy Corner.
Nifty jQuery Corner.
Transparent Corners.
jQuery Corner Gallery.
Gradient Plugin.
文字和超链接(Text and Links)jQuery Spoiler plugin.
Text Highlighting.
Disable Text Select Plugin.
jQuery Newsticker.
Auto line-height Plugin.
Textgrad - a text gradient plugin.
LinkLook - a link thumbnail preview.
pager jQuery Plugin.
shortKeys jQuery Plugin.
jQuery Biggerlink.
jQuery Ajax Link Checker.
鼠标提示(Tooltips)jQuery Plugin - Tooltip.
jTip - The jQuery Tool Tip.
clueTip.
BetterTip.
Flash Tooltips using jQuery.
ToolTip.
 
2007-12-25 4:03
时间、日期和颜色选取(Time, Date and Color Picker)jQuery UI Datepicker.
jQuery date picker plugin.
jQuery Time Picker.
Time Picker.
ClickPick.
TimePicker.
Farbtastic jQuery Color Picker Plugin.
Color Picker by intelliance.fr.
投票插件(Rating Plugins)jQuery Star Rating Plugin.
jQuery Star Rater.
Content rater with asp.net, ajax and jQuery.
Half-Star Rating Plugin.
搜索插件(Search Plugins)jQuery Suggest.
jQuery Autocomplete.
jQuery Autocomplete Mod.
jQuery Autocomplete by AjaxDaddy.
jQuery Autocomplete Plugin with HTML formatting.
jQuery Autocompleter.
AutoCompleter (Tutorial with PHP&MySQL).
quick Search jQuery Plugin.
编辑器(Inline Edit & Editors)jTagEditor.
WYMeditor.
jQuery jFrame.
Jeditable - edit in place plugin for jQuery.
jQuery editable.
jQuery Disable Text Select Plugin.
Edit in Place with Ajax using jQuery.
jQuery Plugin - Another In-Place Editor.
TableEditor.
tEditable - in place table editing for jQuery.
多媒体、视频、Flash等(Audio, Video, Flash, SVG, etc)jMedia - accessible multi-media embedding.
JBEdit - Ajax online Video Editor.
jQuery MP3 Plugin.
jQuery Media Plugin.
jQuery Flash Plugin.
Embed QuickTime.
SVG Integration.
图片(Photos/Images/Galleries)ThickBox.
jQuery lightBox plugin.
jQuery Image Strip.
jQuery slideViewer.
jQuery jqGalScroll 2.0.
jQuery - jqGalViewII.
jQuery - jqGalViewIII.
jQuery Photo Slider.
jQuery Thumbs - easily create thumbnails.
jQuery jQIR Image Replacement.
jCarousel Lite.
jQPanView.
jCarousel.
Interface Imagebox.
Image Gallery using jQuery, Interface & Reflactions.
simple jQuery Gallery.
jQuery Gallery Module.
EO Gallery.
jQuery ScrollShow.
jQuery Cycle Plugin.
jQuery Flickr.
jQuery Lazy Load Images Plugin.
Zoomi - Zoomable Thumbnails.
jQuery Crop - crop any image on the fly.
Image Reflection.
 
2007-12-25 4:03
概述jQuery 是继 prototype 之后又一个优秀的 Javascript 框架。其宗旨是—写更少的代码,做更多的事情。它是轻量级的 js 库(压缩后只有21k) ,这是其它的 js 库所不及的,它兼容 CSS3,还兼容各种浏览器(IE 6.0+, FF 1.5+, Safari 2.0+, Opera 9.0+)。 jQuery 是一个快速的,简洁的 javaScript 库,使用户能更方便地处理 HTML documents、events、实现动画效果,并且方便地为网站提供 AJAX 交互。 jQuery 还有一个比较大的优势是,它的文档说明很全,而且各种应用也说得很详细,同时还有许多成熟的插件可供选择。 jQuery 能够使用户的 html 页保持代码和 html 内容分离,也就是说,不用再在 html 里面插入一堆js来调用命令了,只需定义 id 即可。今天在Kollermedia.at上发现了一篇JQuery插件列表的文章,特推荐如下。
文件上传(File upload)Ajax File Upload.
jQUploader.
Multiple File Upload plugin.
jQuery File Style.
Styling an input type file.
Progress Bar Plugin.
表单验证(Form Validation)jQuery Validation.
Auto Help.
Simple jQuery form validation.
jQuery XAV - form validations.
jQuery AlphaNumeric.
Masked Input.
TypeWatch Plugin.
Text limiter for form fields.
Ajax Username Check with jQuery.
表单-选取框(Form - Select Box stuff)jQuery Combobox.
jQuery controlled dependent (or Cascadign) Select List.
Multiple Selects.
Select box manipulation.
Select Combo Plugin.
jQuery - LinkedSelect
Auto-populate multiple select boxes.
Choose Plugin (Select Replacement).
表单基本、输入框、选择框等(Form Basics, Input Fields, Checkboxes etc.)jQuery Form Plugin.
jQuery-Form.
jLook Nice Forms.
jNice.
Ping Plugin.
Toggle Form Text.
ToggleVal.
jQuery Field Plugin.
jQuery Form’n Field plugin.
jQuery Checkbox manipulation.
jTagging.
jQuery labelcheck.
Overlabel.
3 state radio buttons.
ShiftCheckbox jQuery Plugin.
Watermark Input.
jQuery Checkbox (checkboxes with imags).
jQuery SpinButton Control.
jQuery Ajax Form Builder.
jQuery Focus Fields.
jQuery Time Entry.
 
2007-12-23 19:21


--------------------------------------------------------------------------------


正则表达式用于字符串处理,表单验证等场合,实用高效,但用到时总是不太把握,以致往往要上网查一番。我将一些常用的表达式收藏在这里,作备忘之用。本贴随时会更新。

匹配中文字符的正则表达式:

[\u4e00-\u9fa5]
匹配双字节字符(包括汉字在内):

[^\x00-\xff]
应用:计算字符串的长度(一个双字节字符长度计2,ASCII字符计1)

String.prototype.len=function(){ return this.replace([^\x00-\xff]/g,"aa").length; }
匹配空行的正则表达式:

\n[\s|]*\r
匹配HTML标记的正则表达式:

/<(.*)>.*<\/\1>|<(.*) \/>/
匹配首尾空格的正则表达式:

(^\s*)|(\s*$)
应用:j avascript中没有像v bscript那样的trim函数,我们就可以利用这个表达式来实现,如下:

String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
利用正则表达式分解和转换IP地址
下面是利用正则表达式匹配IP地址,并将IP地址转换成对应数值的Javascript程序:

function IP2V(ip)
{
    re=/(\d+)\.(\d+)\.(\d+)\.(\d+)/g //匹配IP地址的正则表达式
    if(re.test(ip))
    {
        return RegExp.$1*Math.pow(255,3))+RegExp.$2*Math.pow(255,2))+RegExp.$3*255+RegExp.$4*1
    }
    else
    {
        throw new Error("Not a valid IP address!")
    }
}
不过上面的程序如果不用正则表达式,而直接用split函数来分解可能更简单,程序如下:

var ip="10.100.20.168"
ip=ip.split(".")
alert("IP值是:"+(ip[0]*255*255*255+ip[1]*255*255+ip[2]*255+ip[3]*1))
匹配Email地址的正则表达式:

\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
匹配网址URL的正则表达式:

http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
利用正则表达式去除字串中重复的字符的算法程序:[*注:此程序不正确]

var s="abacabefgeeii"
var s1=s.replace(/(.).*\1/g,"$1")
var re=new RegExp("["+s1+"]","g")
var s2=s.replace(re,"")
alert(s1+s2) //结果为:abcefgi
*注
===============================
如果var s = “abacabefggeeii”
结果就不对了,结果为:abeicfgg
正则表达式的能力有限
===============================

我原来在CSDN上发贴寻求一个表达式来实现去除重复字符的方法,最终没有找到,这是我能想到的最简单的实现方法。思路是使用后向引用取出包括重复的字符,再以重复的字符建立第二个表达式,取到不重复的字符,两者串连。这个方法对于字符顺序有要求的字符串可能不适用。

得用正则表达式从URL地址中提取文件名的javascript程序,如下结果为index

s=http://www.wmstudio.cn/index.htm
s=s.replace(/(.*\/){ 0, }([^\.]+).*/ig,"$2")
alert(s)
利用正则表达式限制网页表单里的文本框输入内容:

用正则表达式限制只能输入中文:

onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))"
用正则表达式限制只能输入全角字符:

onkeyup="value=value.replace(/[^\uFF00-\uFFFF]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\uFF00-\uFFFF]/g,''))"
用正则表达式限制只能输入数字:

onkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"
用正则表达式限制只能输入数字和英文:

onkeyup="value=value.replace(/[\W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"
匹配非负整数(正整数 + 0)

^\d+$
匹配正整数

^[0-9]*[1-9][0-9]*$
匹配非正整数(负整数 + 0)

^((-\d+)|(0+))$
匹配负整数

^-[0-9]*[1-9][0-9]*$
匹配整数

^-?\d+$
匹配非负浮点数(正浮点数 + 0)

^\d+(\.\d+)?$
匹配正浮点数

^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$
匹配非正浮点数(负浮点数 + 0)

^((-\d+(\.\d+)?)|(0+(\.0+)?))$
匹配负浮点数

^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$
匹配浮点数

^(-?\d+)(\.\d+)?$
匹配由26个英文字母组成的字符串

^[A-Za-z]+$
匹配由26个英文字母的大写组成的字符串

^[A-Z]+$
匹配由26个英文字母的小写组成的字符串

^[a-z]+$
匹配由数字和26个英文字母组成的字符串

^[A-Za-z0-9]+$
匹配由数字、26个英文字母或者下划线组成的字符串

^\w+$
匹配email地址

^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$
匹配url

^[a-zA-z]+://匹配(\w+(-\w+)*)(\.(\w+(-\w+)*))*(\?\S*)?$
匹配html tag

<\s*(\S+)(\s[^>]*)?>(.*?)<\s*\/\1\s*>
Visual Basic & C# Regular Expression
1.确认有效电子邮件格式
下 面的示例使用静态 Regex.IsMatch 方法验证一个字符串是否为有效电子邮件格式。如果字符串包含一个有效的电子邮件地址,则 IsValidEmail 方法返回 true,否则返回 false,但不采取其他任何操作。您可以使用 IsValidEmail,在应用程序将地址存储在数据库中或显示在 ASP.NET 页中之前,筛选出包含无效字符的电子邮件地址。

[Visual Basic]

Function IsValidEmail(strIn As String) As Boolean
' Return true if strIn is in valid e-mail format.
Return Regex.IsMatch(strIn, ("^([\w-\.]+)@((\[[0-9]{ 1,3 }\.[0-9]{ 1,3 }\.[0-9]{ 1,3 }\.)|(([\w-]+\.)+))([a-zA-Z]{ 2,4 }|[0-9]{ 1,3 })(\]?)$")
End Function
[C#]

bool IsValidEmail(string strIn)
{
// Return true if strIn is in valid e-mail format.
return Regex.IsMatch(strIn, @"^([\w-\.]+)@((\[[0-9]{ 1,3 }\.[0-9]{ 1,3 }\.[0-9]{ 1,3 }\.)|(([\w-]+\.)+))([a-zA-Z]{ 2,4 }|[0-9]{ 1,3 })(\]?)$");
}
2.清理输入字符串
下 面的代码示例使用静态 Regex.Replace 方法从字符串中抽出无效字符。您可以使用这里定义的 CleanInput 方法,清除掉在接受用户输入的窗体的文本字段中输入的可能有害的字符。CleanInput 在清除掉除 @、-(连字符)和 .(句点)以外的所有非字母数字字符后返回一个字符串。

[Visual Basic]

Function CleanInput(strIn As String) As String
' Replace invalid characters with empty strings.
Return Regex.Replace(strIn, "[^\w\.@-]", "")
End Function
[C#]

String CleanInput(string strIn)
{
    // Replace invalid characters with empty strings.
    return Regex.Replace(strIn, @"[^\w\.@-]", "");
}
3.更改日期格式
以下代码示例使用 Regex.Replace 方法来用 dd-mm-yy 的日期形式代替 mm/dd/yy 的日期形式。

[Visual Basic]

Function MDYToDMY(input As String) As String
Return Regex.Replace(input, _
"\b(?<month>\d{ 1,2 })/(?<day>\d{ 1,2 })/(?<year>\d{ 2,4 })\b", _
"${ day }-${ month }-${ year }")
End Function
[C#]

String MDYToDMY(String input)
{
    return Regex.Replace(input,"\\b(?<month>\\d{ 1,2 })/(?<day>\\d{ 1,2 })/(?<year>\\d{ 2,4 })\\b","${ day }-${ month }-${ year }");
}
Regex 替换模式
本示例说明如何在 Regex.Replace 的替换模式中使用命名的反向引用。其中,替换表达式 ${ day } 插入由 (?…) 组捕获的子字符串。

有几种静态函数使您可以在使用正则表达式操作时无需创建显式正则表达式对象,而 Regex.Replace 函数正是其中之一。如果您不想保留编译的正则表达式,这将给您带来方便

4.提取 URL 信息
以下代码示例使用 Match.Result 来从 URL 提取协议和端口号。例如,“http://www.penner.cn:8080……将返回“http:8080”。

[Visual Basic]

Function Extension(url As String) As String
Dim r As New Regex("^(?<proto>\w+)://[^/]+?(?<port>:\d+)?/", _
RegexOptions.Compiled)
Return r.Match(url).Result("${ proto }${ port }")
End Function
[C#]

String Extension(String url)
{
    Regex r = new Regex(@"^(?<proto>\w+)://[^/]+?(?<port>:\d+)?/",
    RegexOptions.Compiled);
    return r.Match(url).Result("${ proto }${ port }");
}
只有字母和数字,不小于6位,且数字字母都包含的密码的正则表达式
在C#中,可以用这个来表示:

"\w{ 6 }(\w+)*"
一个将需要将路径字符串拆分为根目录和子目录两部分的算法程序,考虑路径格式有:C:\aa\bb\cc ,\\aa\bb\cc , ftp://aa.bb/cc 上述路径将分别被拆分为:C:\和aa\bb\cc ,\\aa 和 \bb\cc , ftp:// 和 aa.bb/cc 用javascript实现如下:

var strRoot,strSub
var regPathParse=/^([^\\^\/]+[\\\/]+|\\\\[^\\]+)(.*)$/
if(regPathParse.test(strFolder))
{
    strRoot=RegExp.$1
    strSub=RegExp.$2
}
Posted by should at 2006-06-12 10:49:11 | Read More | Edit | Comments(0) | Trackback(0)


正则表达式基本元素    -[多收了三五斗]
元字符:
.: 用于匹配除换行符以外的任意单个字符。在awk中,句点也能匹配换行符

* :用于与它前面的正则表达式的零个或多个出现匹配,该表达式通常是一个字符。在正则表达式中,*本身不匹配任何字符,.*匹配任意数目的字符;而shell中,*本身就具有这样的含义。

[...] :匹配方括号中的字符类中的任意一个。如果方括号中第一个字符为脱字符号(^),则表示否定匹配,即匹配除了换行符和类中列出的那些字符以外的所有字符。 在awk中,也匹配换行符。连字符(-)用于表示字符的范围。如果类中的第一个字符为右方括号(])则表示它是类的成员。所有其他的元字符在被指定为类中 的成员时都会失去它们原来的含义。

^: 如果作为正则表达式的第一个字符,则表示匹配行的开始。在awk中匹配字符串的开始,即使字符串包含嵌入的换行符。

$ :如果作为正则表达式的最后一个字符,则表示匹配行的结尾。在awk中匹配字符串的结尾,即使字符串包含嵌的换行符。

\{n,m\}: 匹配它前面某个范围内单个字符出现的次数(包括由正则表达式指定的字符)。\{n\}将匹配n次出现,\{n,\}至少匹配n次出现,而且\{n,m\}匹配n和m之间的任意次出现。

\ :转义随后的特殊字符


扩展的元字符(egrep, awk)
+ :匹配前面的正则表达式的一次或多次出现
? :匹配前面的正则表达式的零次或多次出现
| :指定可以匹配其前面的或后面的正则表达式
(): 对正则表达式分组
{n,m}: 匹配它前面某个范围内单个字符出现的次数(包括由正则表达式指定的字符)。{n}表示匹配n次出现,{n,}至少匹配n次出现,{n,m}匹配n和m之间的任意次出现。(用于POSIX的egrep和POSIX的awk,而非传统的egrep和awk)


字符类[]的用法
其中的特殊字符:
\ 转移任意特殊字符(只用于awk中)
- 不用在第一或最后一个位置时,表示范围
^ 仅当在第一个位置时表示反转匹配。将类中所有字符都排除在匹配之外,除换行符以外的没有列在方括号中的任意字符都将被匹配。
eg.
[a-zA-Z][.?!]:匹配后面跟由句点、问号和感叹号的任意小写或大写字母

POSIX字符类补充:
POSIX标准对正则表达式字符和操作符的含义进行了形式化。这种标准定义了两类正则表达式:
基本正则表达式(grep,sed使用这种正则表达式)和扩展的正则表达式(egrep和awk使用)
POSIX标准增强了匹配不在英文字母表中的字符的字符类的功能。
POSIX标准中称“字符类”为“括号表达式”。在括号表达式中,除了有字面字符(如a,!等),还有其他标记:
·字符类:由[:和:]包围的关键字组成的POSIX字符类。如:
      [:alnum:]    可打印的字符(包括空白字符)
      [:alpha:]     字母字符
·整理(collating)字符:整理符号是多字符的序列,表示这些字符应该被看成一个单元,由[.和.]包围的字符组成。
·等价类:等价类列出了应该看做是等价的字符集,例如英文的e和法文的e,它由地区化的字符元素组成。由[=和=]包围组成。

^和$在sed和grep中,只要不是出现在pattern的特殊位置,均不作特殊处理。而awk中,无论他们在什么位置,都被解释成特殊意义,除非用\

后记:

      本想找找看如何匹配汉字,但从linux下的grep和awk等工具的manual中看,似乎他们没有提供这样的功能。倒是搜到了javascript中 如何匹配中文字符的正则表达式,ms其中使用的是字符编码来匹配的。看来,要写匹配中文的正则表达式,只能借助具体语言来看了

 
2007-12-22 23:46

我每天都要用到操作系统的文件搜索功能,我以前一直都用WIN2000,在win2000上这个功能很好用,可最近换了台电脑(原来那台太老了),同时我也想用用XP,虽然XP出来有五六年了,我还没怎么用过。谁知道一用就发现很多地方不尽我心意,因为软件装得多了,也就不想再换回win2000了,XP中最让我不能忍受的就是那个文件搜索功能一点用都没有,当我想搜索某个词在哪些文件中时,这个破功能装装模作样的搜索后出来一个没有结果可以显示,要是真的没有也就算了,明明是有的,它也出来没结果可以显示,真是气人,于是在网上找一下看看有没有解决方法,还算运气好,下面是我调试成功的方法:

运行regedit,编辑注册表
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ContentIndex
右侧FilterFilesWithUnknownExtensions子键(REG_DEWORD类型)的键值改为1。

另:如果你熟悉Windows2000及以前版本的搜索方式,对Windows XP的动画搜索助手和分类别的搜索方式不习惯,那么你可以通过改变搜索属性来找回你熟悉的搜索模式。

搜索里有个“改变首选项”,单击后,将“改变文件和文件夹搜索行为”设置为“高级”即可。

 
2007-12-21 23:14

该文由www.qqwm.com (wmstudio.cn)原创,转载请写明出处

libxml:    ftp://xmlsoft.org/libxml2/
xpm:    http://koala.ilog.fr/ftp/pub/xpm/
gd:    http://www.boutell.com/gd/(http://www.libgd.org/Downloads)
jpegsrc:    http://www.ijg.org/
libpng:    http://sourceforge.net/projects/libpng/
zlib:    http://sourceforge.net/projects/zlib/
freetype:    http://sourceforge.net/projects/freetype/

postgresql:    http://www.postgresql.org/
phppgadmin:    http://phppgadmin.sourceforge.net/








------------------------------------------
|             Apache安装                    |
------------------------------------------
安装apache,(php5安装环境需要apache2.0.46以上版本,下载的时候注意!)
#tar zxvf httpd-2.0.50.tar.gz
#cd httpd-2.0.50
#./configure --prefix=/usr/local/apache --enable-module=so
#make
#make install

编辑/usr/local/apache/conf/httpd.conf:
在DirectoryIndex后加上index.php
(AddDefaultCharset后改为GB2312)

------------------------------------------
|           mode_perl安装                   |
------------------------------------------

使用下面的命令安装,安装脚本是一个perl程序,所以用perl来安装。这个安装的参数看上去比较乱,我试了很多次才编译出来的mode_perl.so.
# tar -zxf mod_perl-2.0.2.tar.gz
#cd mod_perl-2.0.2
#perl Makefile.PL
#/usr/local/apache/bin/apxs
#make
#make install

如果这个安装程序没有将mode_perl.so放到apache/modules目录,直接拷过去即可

------------------------------------------
|                mysql安装                      |
------------------------------------------
如果用rpm按装MYSQL要安装三个RPM后在编译PHP时才能找到MYSQL的header,直接--with-mysql就行了,不用指定路径
Server    (MySQL-server-standard-5.0.24-0.rhel3.i386.rpm)
Client    (MySQL-client-standard-5.0.24-0.rhel3.i386.rpm)
Headers and libraries    (MySQL-devel-standard-5.0.24-0.rhel3.i386.rpm)



------------------------------------------
|            PostgreSql安装                  |
------------------------------------------

# tar zxvf postgresql-8.1.4.tar.gz
# cd postgresql-8.1.4
# ./configure
    (默认就是安装在/usr/local/pgsql,所以编译时不用再加--prefix=/usr/local/pgsql)
# gmake
# su
# gmake install
# adduser postgres
# mkdir /usr/local/pgsql/data
# chown postgres /usr/local/pgsql/data
# su - postgres
$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
    (
    如果出现找不到语言编码用
    /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data -E unicode
    或者
    /usr/local/pgsql/bin/initdb --no-locale -D /usr/local/pgsql/data
    )
$ /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data &
$ /usr/local/pgsql/bin/psql test

# /sbin/ldconfig /usr/local/pgsql/lib(要用root用户)

打开 /etc/profile
添加
PATH=/usr/local/pgsql/bin:$PATH
export PATH

源代码安装目录,复制contrib/start-scripts/linux到/etc/rc.d/init.d/,改名字postgresql
记得更改其属性为可执行
/etc/rc.d/init.d/postgresql start; 命令行,起动postgresql服务
/etc/rc.d/init.d/postgresql restart;命令行,重新起动postgresql服务
/etc/rc.d/init.d/postgresql stop;命令行,kill掉postgresql服务
在/etc/rc.d/rc.local中加入一行
/etc/rc.d/init.d/postgresql start;
或 service postgresql start
都可以自动起动postgresql服务


打开/usr/local/pgsql/data/pg_hba.conf
添加
host    all         all         127.0.0.1          trust              md5
host    all         postgres    127.0.0.1      255.255.255.255     md5



------------------------------------------
|            PHP组件安装                    |
------------------------------------------
libxml:    ftp://xmlsoft.org/libxml2/
zlib:    http://sourceforge.net/projects/zlib/
jpegsrc:    http://www.ijg.org/
libpng:    http://sourceforge.net/projects/libpng/
freetype:    http://sourceforge.net/projects/freetype/



安装libxml
# tar -zxf libxml2-2.6.26.tar.gz
# cd libxml2-2.6.26
# ./configure --prefix=/usr/local/libxml2 (# ./configure (xml默认安装就可以,不要指定路径了,因为安装时php可能找不到它,PHP5只支持libxml2-2.5.10以上版本))
# make
# make install


安装zlib
# tar -zxf zlib-1.2.3.tar.gz
# cd zlib-1.2.3
# ./configure --prefix=/usr/local/zlib2 (注意,如果您以前没有安装zlib,可以不指定路径,我是没有删除以前的低版本才指定的!以下雷同!)
# make
# make install

安装jpeg
如果你选择默认安装,可能很顺利,指定路径后,请先创建以下文件夹
# mkdir /usr/local/jpeg6
# mkdir /usr/local/jpeg6/include
# mkdir /usr/local/jpeg6/lib
# mkdir /usr/local/jpeg6/bin
# mkdir /usr/local/jpeg6/man
# mkdir /usr/local/jpeg6/man/man1

# tar -zxf jpegsrc.v6b.tar.gz
# cd jpeg-6b/
# ./configure --prefix=/usr/local/jpeg6
# make
# make install-lib
# make install

安装libpng:
# tar -zxf libpng-1.2.12.tar.gz
# cd libpng-1.2.12
# ./configure --prefix=/usr/local/libpng2
# make
# make install

安装freetype:
# tar -zxf freetype-2.1.9.tar.gz
# cd freetype-2.1.9
# ./configure --prefix=/usr/local/freetype2
# make
# make install

安装gd库:
# tar -zxf gd-2.0.33.tar.gz
# cd gd-2.0.33
# ./configure --prefix=/usr/local/gd2 --with-zlib=/usr/local/zlib2/ --with-png=/usr/local/libpng2/ --with-jpeg=/usr/local/jpeg6/ --with-freetype=/usr/local/freetype2/ (请指定及格插件的安装路径,否则安装php的时候可能出错!)
# make
# make install


------------------------------------------
|                 PHP安装                     |
------------------------------------------

安装php5:
# tar -zxf php-5.1.6.tar.gz
# cd php-5.1.6
# ./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache/bin/apxs --with-jpeg-dir=/usr/local/jpeg6/ --with-png-dir=/usr/local/libpng2/ --with-gd=/usr/local/gd2/ --with-freetype-dir=/usr/local/freetype2/ --enable-mbstring=all --enable-trace-vars --with-zlib-dir=/usr/local/zlib2/ --with-mysql --with-pgsql=/usr/local/pgsql
# make
# make install
# cp php.ini-dist /usr/local/php5/lib/php.ini
# /usr/local/apache/bin/apachectl restart(重启Apache)


------------------------------------------
|         ZendOptimizer安装               |
------------------------------------------

#tar zxvf ZendOptimizer-3.0.1-linux-glibc21-i386.tar.gz
#cd ZendOptimizer-3.0.1-linux-glibc21-i386
#./install.sh
安装的时候注意输入正确的安装apache的路径等内容!
安装完毕,再看看phpinfo页面的zend选项就发现了!!



------------------------------------------
|            phppgadmin配置                |
------------------------------------------

打开conf/config.inc.php
$conf['servers'][0]['host'] = '127.0.0.1';
$conf['servers'][0]['defaultdb'] = 'test';(这个数据库是先建好了的,也可以根据自己建的数据库填写这个数据名,如果pgsql是8.1以上的,可以用“postgres”)
$conf['extra_login_security'] = false;

------------------------------------------
|            phpmyadmin配置               |
------------------------------------------
很简单的,这里不记录了
==========================================================

 
2007-12-14 16:18

想在新程序里用jquery,调试了十几个小时,总算调试好了,结果发现把jquery库及插件调进到网页里,打开网页时明显变慢,在本机上调试都有明显的变慢,那在网上就不用说了。

jquery库是方便了写程序的人,可是写出来的程序是为了方便用户的啊,一个网页调用几百K的js代码再加上其自动处理所占用的时间,使得初次打开网页时有明显的变慢现象。

放弃使用jquery库算了,白调试这么久,白打工

 
   
 
 
文章分类
 
   
 
文章存档
 
     
 
最新文章评论
  

[表情]
 

转帖了
 

thank you
 

[表情]
 

回复1232:
   
帮助中心 | 空间客服 | 投诉中心 | 空间协议
©2012 Baidu