在PHP中,我们打印一个数组或者对象的时候,都是用print_r,相对比较直观,可是javascript就不行。翻了翻资料,也看到一些代码的写法。这里是一个简单的处理(不能打印window,document等对象):
JavaScript代码
- function print_r( $value ){
- if($value.constructor == Array || $value.constructor == Object ){
- document.write("<ul>");
- for (var $i in $value){
- if($value[$i].constructor == Array || $value[$i].constructor == Object ){
- document.write("<li>["+$i+"] => " + typeof( $value ) + " </li><ul>");
- print_r($value[$i]);
- document.write("</ul>");
- }else{
- document.write("<li>["+$i+"] => " + $value[$i] + "</li>");
- }
- }
- document.write("</ul>");
- }
- }
- var s = {};
- s.i = '123';
- s.o = {};
- s.o.test = 'tt';
- print_r(s);
然后看了一下phpjs.org,它上面的print_r就比较复杂了。。。
JavaScript代码
- function print_r (array, return_val) {
-
-
-
-
-
-
-
-
-
-
-
- var output = "", pad_char = " ", pad_val = 4, d = this.window.document; var getFuncName = function (fn) {
- var name = (/\W*function\s+([\w\$]+)\s*\(/).exec(fn);
- if (!name) {
- return '(Anonymous)';
- } return name[1];
- };
-
- var repeat_char = function (len, pad_char) {
- var str = ""; for (var i=0; i < len; i++) {
- str += pad_char;
- }
- return str;
- };
- var formatArray = function (obj, cur_depth, pad_val, pad_char) {
- if (cur_depth > 0) {
- cur_depth++;
- }
- var base_pad = repeat_char(pad_val*cur_depth, pad_char);
- var thick_pad = repeat_char(pad_val*(cur_depth+1), pad_char);
- var str = "";
- if (typeof obj === 'object' && obj !== null && obj.constructor && getFuncName(obj.constructor) !== 'PHPJS_Resource') {
- str += "Array\n" + base_pad + "(\n";
- for (var key in obj) {
- if (obj[key] instanceof Array) {
- str += thick_pad + "["+key+"] => "+formatArray(obj[key], cur_depth+1, pad_val, pad_char); } else {
- str += thick_pad + "["+key+"] => " + obj[key] + "\n";
- }
- }
- str += base_pad + ")\n"; } else if (obj === null || obj === undefined) {
- str = '';
- } else {
- str = obj.toString();
- }
- return str;
- };
-
- output = formatArray(array, 0, pad_val, pad_char);
- if (return_val !== true) {
- if (d.body) {
- this.echo(output);
- } else {
- try {
- d = XULDocument;
- this.echo('<pre xmlns="http://www.w3.org/1999/xhtml" style="white-space:pre;">'+output+'</pre>');
- } catch (e) {
- this.echo(output);
- }
- }
- return true; } else {
- return output;
- }
- }
果然是没有做不到的事,只有想不到的事呀。。。(上面的phpjs.org的print_r需要echo方法,请到phpjs.org下载)
由CAPCOM负责开发的格斗游戏《街头霸王4》(Street Fighter 4)最新试玩截图公布,本作将承袭系列作传统2D玩法,并采用最新的3D绘图技术,以更华丽的方式重现原作独特的2D绘图风格。PC版发售日期未 定,XBOX360/PS3即将2月17日发售。
另外,CAPCOM透露将推出内含限量非卖版人偶模型(PS3 版为隆,Xbox 360 版为深红毒蛇)、Studio 4C 制作之65分钟高分辨率动画影片(PS3版为BD蓝光影片,Xbox 360 版为专用高分辨率DVD影片,非一般 DVD 影片)、原声配乐 CD、攻略指引手册与独家下载内容的典藏版,定价 79.99美元。
以上内容来自于:http://www.lingaoyi.com/screens/new-street-fighter-4-screenshots/,同时以下图片也来自于该站(我只取了两张与我有关的图片)
更多图片请去该网站查看。。。


没想到啊,连微软也加入了openId的行列了。
看来openId对现在的网络的影响太大了,只是它由谁来管理呢?做为一个商业网站,是没有人会愿意使用OPENID的,但是对于社交化网络,OPENID就显得有点必要了,毕竟没有谁会愿意到处注册userid这类的,谁知道几年后还记不记得自己所设的密码?我的密码找回问题又是什么?
Windows Live ID Commits to Support OpenID
Beginning today, Windows Live ID is publicly committing to support the OpenID digital identity framework with the announcement of the public availability of a Community Technology Preview (CTP) of the Windows Live ID OpenID Provider.
You will soon be able to use your Windows Live ID account to sign in to any OpenID Web site!
The Windows Live ID OpenID Provider (OP) enables anyone with a Windows Live ID account to set up an OpenID alias and to use that alias for identification at an increasing number of OpenID 2.0 relying party sites-for example: Plaxo, Pibb, StackOverflow.com and Wikispaces.
What is OpenID?
The official answer from the OpenID Foundation (the guardians of the OpenID specs) is that "OpenID is a free and easy way to use a single digital identity across the Internet." (Source: http://openid.net/)
OpenID is an emerging, de facto standard Web protocol for user authentication. It helps eliminate the need for multiple user names across different Web sites, thereby simplifying a user's online experience. Stated another way, you can reuse your OpenID account at different Web sites without having to create a new user name and password at each site you use.
More information about OpenID is available at http://openid.net.
Windows Live ID OpenID Provider - October 2008 (CTP)
The initial release is a Community Technology Preview (CTP) Release in the Windows Live ID Integration (INT) environment. It is intended primarily for relying-party Web sites and developers of relying-party client libraries, to enable them to test the interoperability of their implementations against the Windows Live ID OP endpoint and flush out any bugs or incompatibilities.
Note that the Windows Live ID OP supports only the OpenID 2.0 protocol.
The Windows Live ID INT environment is separate from the main Production environment, and is for testing purposes only. If you have not already created a Windows Live ID user account for testing in INT, you can do so at http://login.live-int.com/.
After you have your Windows Live ID account in INT, go to https://login.live-int.com/beta/ManageOpenID.srf to set up your OpenID alias on that test account.
NOTE: INT accounts are for testing purposes only and are NOT intended to be permanent user accounts. They do not allow access to Windows Live services in Production.
Windows Live ID OpenID Provider - Future Release Plans
The current Technology Preview release is for testing purposes only, and is not intended for widespread adoption at this stage. After a period of industry testing and feedback, we will be incorporating any necessary fixes and feature enhancements into the next revision, to be released to Production sometime in 2009.
We do NOT recommend that anyone use their INT alias as their permanent OpenID account at this time; users should wait until the final release of the OP to Production.
Open Standards Support
All Windows Live product teams are committed to supporting open standards where such standards are relevant to our work and when they reach a sufficient level of maturity, and the Windows Live ID Team is no exception. We have been tracking the evolution of the OpenID specification, from its birth as just a dream and a vision through its development into a mature, de facto standard with terms that make it viable for us to implement it now.
We look forward to making it easier for our users to access the Web sites they use, by reducing their need to create additional identity accounts. That is the promise of OpenID. We are happy to support that goal by providing OpenID-based sign-in functionality to Windows Live ID account holders.
Try It Now. Tell Us What You Think
We want you to try the Windows Live ID OpenID Provider CTP release, let us know your feedback, and tell us about any problems you find.
To prepare:
- Go to http://login.live-int.com/ and use the Sign up for an account link to set up a Windows Live ID test account in the INT environment.
- Go to https://login.live-int.com/beta/ManageOpenID.srf to set up your OpenID test alias.
Then:
- Users - At any Web site that supports OpenID 2.0, type openid.live-INT.com in the OpenID login box to sign in to that site by means of your Windows Live ID OpenID alias.
- Library developers - Test your libraries against the Windows Live ID OP endpoint and let us know of any problems you find.
- Web site owners - Test signing in to your site by using a Windows Live ID OpenID alias and let us know of any problems you find.
You can send us feedback at:
For more information, see the Windows Live ID blog: http://winliveid.spaces.live.com/Blog/cns!AEE1BB0D86E23AAC!1745.entry
Jorgen Thelin
使用ThinkPHP自带的模版引擎处理模版问题时,一般情况下不会有什么问题。
但是,在处理一些XHTML模版时,可能会遇到以下问题,比如,模版作者在制作模版时,为了规范页面,往往在文件头部加上<?xml version="1.0" encoding="utf-8"?>,表明文件是属于XML规范,所有的标签都必须遵循XML的相关规定。
然而,默认的ThinkPHP模版引擎在处理的时候会出现错误,处理这个错误的情况有以下几种办法。
第一种方法:你尝试关闭PHP的短标签功能
第二种方法:试着用<literal></literal>标签把XML的标签包含起来,即
<literal><?xml version="1.0" encoding="utf-8"?></literal>
第三种方法:修改ThinkPHP/Lib/Think/Template/ThinkTemplate.class.php的compiler函数,在函数的最后一行return $templContent;前加入
PHP代码
-
- $tmplContent = preg_replace('/(<?(?!php|=|$))/i', '<?php echo '\1'; ?>'."n", $tmplContent );
任何一种方法理论上都可以,第一种第二种方法实在不行的时候,再用第三种,毕竟第三种方法是改动核心的,如果以后更新核心库,可能会不当心就覆盖掉了。
不过,流年说过了,他已经更新了模板引擎的解析类,并且专门判断了是否开启了短标签,如果开启的话会自动用第三种方法解析。更新下SVN的ThinkTemplate.class.php 文件就可以了(可能压缩包还没有同步更新[2008-04-22])。