shtml中的脚本 – SSI 服务器端包含 (Server Side Includes)

服务器端包含

 

介绍

服务器端包含(Server Side Includes),通常简称为SSI,是HTML页面中的指令,在页面被提供时由服务器进行运算,以对现有HTML页面增加动态生成的内容,而无须通过CGI程序提供其整个页面,或者使用其他动态技术。

对什么时候用SSI,而什么时候用某些程序生成整个页面的权衡,取决于页面中有多少内容是静态,有多少内容需要在每次页面被提供时重新计算。SSI是一种增加小段信息的好方法,诸如当前时间。如果你的页面大部分是在被提供时生成的,那就要另找方案了。

。将服务器信息添加到一个 HTML 文档。包括以下的形式:

<!--#command variablename="value"-->
Whether or not you can use SSI on your site depends on your provider. Ask your favourite support person if you can use SSI, what server software is used and if there are any special techniques, conditions or rules. For example, on my site I can only use SSI in files that have an .shtml extension instead of the normal .html one. You also have to ask what path to files to use.

Unfortunately, not all includes explained here work for all servers. For example, the #hide and #show includes are specific to WebStar. With Apache server software, you can achieve the same things by using #if and #endif.

更改时间格式

Before starting to use server side includes, you need to configure a number of things. For starters, choose a format for date and time you like (the #echo command is explained later in this chapter).

<!–#config timefmt=”%A, %d %B %Y at %H:%M:%S”–>
<!–#echo var=”date_gmt”–>

Below is a table of many of the options you can use. You can also include things like colons, commas and slashes as well as bits of text and HTML. You can mix the elements below at will.

Element Value Example
%a Abbreviated day of the week Sun
%A Day of the week Sunday
%b Abbreviated month name Jan
%B Month in full January
%d Date 1 (and not 01)
%H 24-hour clock hour 13
%I 12-hour clock hour 1
%j Decimal day of the year 360
%m Month number 11
%M Minutes 08
%p AM or PM AM
%S Seconds 09
%U Week of the year (also %W) 49
%w Day of the week number 05
%y Year of the century 95
%Y Year 1995
%Z Time zone EST

Here are some more examples of different formats:

<!–#config timefmt=”Week %U of %y”–>
<!–#echo var=”date_gmt”–>

<!–#config timefmt=”%d/%m/%y, day %j of the year”–>
<!–#echo var=”date_gmt”–>

<!–#config timefmt=”%I:%S %p”–>
<!–#echo var=”date_gmt”–>

The last format you have set will remain valid throughout the rest of the page. However, unless you want to use the default format (which usually is something like 98/07/12:16:45:34) you will have to set your favourite time format in every page that uses server side includes that have to do with time.

更改大小格式

You can also specify the way file sizes are displayed.

<!–#config sizefmt=”bytes”–>
<!–#fsize file=”top.gif”–>
<!–#config sizefmt=”abbrev”–>
<!–#fsize file=”top.gif”–>


The #fsize include is explained later in this chapter. You can see that the “bytes” option gives the size in full in bytes, the “abbrev” option gives the size in kilobytes.

自定义错误消息

You can change the default error message to anything you want. Here is an example of changing the error message and then trying to include the non-existent file “nosuchfile.html”:

<!–#config errmsg=”Sorry, an error occurred. Please mail your complaints to webmaster@somewhere.net”–>

<!–#include file=”nosuchfile.html”–>

There is only one error message available. However, you can change the error message more than once in a single html file:

<!–#config errmsg=”Sorry, an error occurred including nosuchfile.html. Please mail your complaints to webmaster@somewhere.net”–>

<!–#include file=”nosuchfile.html”–>

<!–#config errmsg=”Sorry, an error occurred including nosuchfileagain.html. Please mail your complaints to webmaster@somewhere.net”–>

<!–#include file=”nosuchfileagain.html”–>

Specifying your own error messages will make it easier for you to spot and solve problems. If you want to use more than one error message, you have to make sure that you change the error message before the command it refers to.

包括文件

The include command allows you to dynamically insert other HTML files into the current HTML file. Use it like this:

<!–#include file=”file.shtml”–>

What path to use, again, depends on your provider. Normally it will be a path that is local to the server, so it will not include http://etc. The most sensible use of this command is to take standard bits of your pages such as headers and footer and put them in a separate file. On all of your pages you use the include command to include that file. That way, in order to change the footer on all pages, you only need to change one file. For example, you could make a simple text file that contains:

<P ALIGN=”center”>Copyright 1998 Tom, Dick and Harry<BR>
Please mail us at tom.dick@harry.com</P

You save this file as ssifooter.html and include it in your other files by using:

<!–#include file=”ssifooter.html”–>

The files you include can be plain text files or can include HTML. You don’t need to give them <HEAD> and <BODY> tags, just put in whatever you want to insert. In these files you can use whatever HTML you want and you can make links, etc.

隐藏 / 显示

With the Hide and Show commands you can avoid that your reader sees certain parts of the document:

<P>Now you see me, <!–#hide–> This text is not shown. <!–#show–> now you don’t.</P

Show and Hide can be used to temporary exclude parts of your document. Hide and Show only work under WebStar, so I cannot show you an example here.

根据时间隐藏和显示

The next example shows how to display bits of HTML only after certain days. Comparisons like this always use the default time format of 1998/07/24:17:34:45 no matter what you have done with the timefmt option.

<!–#hide–>
<!–#show after=”1998/06/30″–>
This text is shown after 30 June 1998.
<!–#show–>

<!–#hide–>
<!–#show after=”1999/06/30″–>
This text is shown after 30 June 1999.
<!–#show–>

Or you can show and hide things on specific days using a combination of ‘hide after’ and ‘show after’:

<!–#hide–>
<!–#show during=”1998/07/12″–>
This text is shown on 12 July 1998.
<!–#show–>

<!–#hide–>
<!–#show during=”1998/07/13″–>
This text is shown on 13 July 1998.
<!–#show–>

<!–#hide–>
<!–#show during=”1998/07/14″–>
This text is shown on 14 July 1998.
<!–#show–>

As you can see, you do not have to specify a full date and time but only what is relevant for you. If you would want to show something during 1998 you could use: during=”1998″.

依据时间隐藏和显示

Here is an example of how to show a bit of text only to a user of Netscape’s Navigator:

<!–#hide–>
<!–#show var=”http_user_agent” operator=”contains”
value=”nav”–>
Welcome Netscape Navigator user!
<!–#show–>

<!–#hide–>
<!–#show var=”http_user_agent” operator=”contains”
value=”MSIE”–>
Welcome Internet Explorer user!
<!–#show–>

As you can see in this example, the output of Webstar is by default on. That’s why you start any of these examples by switching the output of (#hide) and then switching it on again if the appropriate condition is fulfilled. At the end of the example you switch the output on again with a #show include. Again, show and hide do not work under Apache so I cannot show you the result here.

随机隐藏和显示

Show and Hide can also be used at random:

<!–#hide–>
<!–#show var=”random” op=”<” value=”50″ –>
Heads
<!–#hide–>
<!–#show var=”random” op=”=>” value=”50″ –>
Tails
<!–#show–>

If you do a couple of reloads, you should see the text change. Of course you can use the same thing to show and hide images or any other HTML. The number that is used by Webstar is a random number ranging from 1 to 99 inclusive. Here is an example for three random texts:

<!–#hide–>
<!–#show var=”random” op=”<” value=”33″ –>
To be or not to be,
<!–#hide–>
<!–#show var=”random” op=”=>” value=”34″ –>
<!–#hide var=”random” op=”>” value=”66″ –>
that’s the question,
<!–#hide–>
<!–#show var=”random” op=”>” value=”66″ –>
my dear Watson.
<!–#show–>

更多的隐藏和显示

In fact you can show and hide text at will using any of the environment variables (see the section on Echo below). This example shows a bit of text to a user with IP address 195.99.40.125:

<!–#hide–>
<!–#show var=”remote_addr” operator=”=” value=”195.99.40.125″–>
Welcome BTinternet user!
<!–#show–>

If you have friends with fixed IP addresses you can leave messages especially for them in the same manner. Finally, you should know which operators are available:

Operator Meaning
“contains” or “con” variable contains the value string
“starts with” or “start” variable starts with the value string
“ends with” or “end” variable ends with the value string
“=” or “==” variable equals the value string
“!=” or “<>” variable does not equal the value string
“<“ variable is less than the value string
“<=” or “=<“ variable is less than or equal to the value string
“>” variable is greater than the value string
“>=” or “=>” variable is greater than or equal to the value string

If 和 Endif

Because this server runs Apache I could not show the examples of #hide and #show. I can, however, demonstrate the #if and #endif includes (if and endif, in turn, do not work under Webstar):

<!–#config timefmt=”%A”–>
<!–#if expr=”$date_gmt = Friday” –>
Hang in there, it’s almost weekend
<!–#elif expr=”($date_gmt = Saturday) || ($date_gmt = Sunday)” –>
Have a nice weekend
<!–#else –>
Have a good day
<!–#endif –>

Hang in there, it’s almost weekend Have a nice weekend Have a good day

The first thing you will notice is that the #if include, opposite to the #hide and #show, does use the date as formatted with timefmt. This has some clear advantages. You can also see that this example is a bit easier to understand the #show and #hide spaghetti that WebStar seems to need. Note that the #if and #endif are obligatory, the #elif and #else are optional. This example uses date_gmt which is London time -ignoring summertime- rather than date_local which depends on where the server is.

The following operators are available:

Operator Meaning
string1 = string2 string1 equals string2
string1 != string2 string1 does not equal string2
string1 < string2 string1 is less than string2
string1 <= string2 string1 is less than or equal to string2
string1 > string2 string1 is greater than string2
string1 >= string2 string1 is greater than or equal to string2

If, Endif 和环境变量

you can use the #if include to show different information to different browsers. Each browser sets the environment variable http_user_agent differently. This is how Netscape Navigator 4.04, Microsoft Internet Exploder and Apple’s Cyberdog respectively do it:

Mozilla/4.04 (Macintosh; I; PPC, Nav)
Mozilla/4.0 (compatible; MSIE 4.0; Mac_PowerPC)
Cyberdog/2.0 (Macintosh; PPC)

As you can see these are all the Macintosh versions. By the way, this is what your own browser makes of http_user_agent: . So this is how to show different information to different browsers:

<!–#if expr=”$HTTP_USER_AGENT=/MSIE/ ” –>
Fight the Microsoft Monopoly. Get Netscape!
<!–#elif expr=”$HTTP_USER_AGENT=/Nav/ ” –>
Welcome Netscape Navigator user!
<!–#elif expr=”$HTTP_USER_AGENT=/Cyberdog/ ” –>
Welcome Apple Cyberdog user!
<!–#else –>
Welcome! So what browser are you using?
<!–#endif –>

Fight the Microsoft Monopoly. Get Netscape! Welcome Netscape Navigator user! Welcome Apple Cyberdog user! Welcome! So what browser are you using?

Note that the /Nav/ I am looking for here is produced by Netscape Navigator, which is Communicator without the news, mail and webeditor modules. The above is obviously not an exhaustive list of browsers, which is why there is also an #else include for all the browsers that are not covered.

The two slashes around MSIE, Nav and Cyberdog in the example above means that the second string is interpreted as a regular expression, commonly used under Unix. In this case it checks if http_user_agent contains that string.

Set

The #set include can be used to create your own variables and assign them a value. Variables can be printed or can be used in #if statements:

<!–#set var=”carmodel” value=”Mercedes” –>
<!–#echo var=”carmodel” –><BR>
<!–#if expr=”$carmodel = Mercedes” –>
That’s a jolly nice car
<!–#endif –>


That’s a jolly nice car

The $ sign in the #if include is needed to ensure that “carmodel” is interpreted as a variable, not as a string.

Echo

ECHO can be used to insert information from the browser and the server into your document, the so-called environment variables. The following possibilities are available:

Document Name: <!–#echo var=”document_name”–>
Document URI: <!–#echo var=”document_uri”–>
Local Date: <!–#echo var=”date_local”–>
GMT Date: <!–#echo var=”date_gmt”–>
Last Modified: <!–#echo var=”last_modified”–>
Server Software: <!–#echo var=”server_software”–>
Server Name: <!–#echo var=”server_name”–>
Server Protocol: <!–#echo var=”server_protocol”–>
Server Port: <!–#echo var=”server_port”–>
Gateway Interface: <!–#echo var=”gateway_interface”–>
Request Method: <!–#echo var=”request_method”–>
Script Name: <!–#echo var=”script_name”–>
Remote Host: <!–#echo var=”remote_host”–>
Remote Address: <!–#echo var=”remote_addr”–>
Remote User: <!–#echo var=”remote_user”–>
Content Type: <!–#echo var=”content_type”–>
Content Length: <!–#echo var=”content_length”–>
HTTP Accept: <!–#echo var=”http_accept”–>
HTTP User Agent (Browser): <!–#echo var=”http_user_agent”–>
HTTP Cookie: <!–#echo var=”http_cookie”–>
Unescaped query string: <!–#echo var=”query_string_unescaped”–>
Query String: <!–#echo var=”query_string”–>
Path Info: <!–#echo var=”path_info”–>
Path Translated: <!–#echo var=”path_translated”–>
Referer: <!–#echo var=”referer”–>
Forwarded: <!–#echo var=”forwarded”–>

Document Name:
Document URI:
Local Date:
GMT Date:
Last Modified:
Server Software:
Server Name:
Server Protocol:
Server Port:
Gateway Interface:
Request Method:
Script Name:
Remote Host:
Remote Address:
Remote User:
Content Type:
Content Length:
HTTP Accept:
HTTP User Agent (Browser):
HTTP Cookie:
Unescaped query string:
Query String:
Path Info:
Path Translated:
Referer:
Forwarded:

Not all ECHO commands always result in information being printed. This can depend on the server, on your browser and on the way you reached this page. The #echo include works both under WebStar and Apache.

Print Environment

If you want to print the entire environment, you do not need to use a whole list of #echo includes. Instead you can use this shortcut.

<PRE> <!–#printenv –> </PRE>



Note that the environment includes the variable “carmodel” that was defined in an earlier example.

执行脚本

You can use a server side include to run a script. This is what I use on my homepage:

<!–#exec cgi=”ssi.demo.cgi”–>

The CGI script (which is in Perl 5) opens a file with a dozen quotes, selects one at random and prints it to the page. The script, by the way, is courtesy of Matt Wright who offers a brilliant collection of scripts.

文件大小

You can insert the size of a file in this way:

<!–#fsize file=”top.gif”–>

This inserts the size of the file top.gif (the logo at the top of this page). As explained earlier in this chapter, you can determine if the size is displayed in full bytes or abbreviated in kilobytes or megabytes.

文件日期

You can insert the date of a file in this way:

<!–#flastmod file=”top.gif”–>

This inserts the date and the time the file top.gif (the logo at the top of this page) was last modified. The format of the date and time can be customized by you as explained earlier in this chapter.

This page has been translated into Spanish language by Maria Ramos from Webhostinghub.com.

 

 

Kloxo-MR 中安装 thirdparty phpMyAdmin

/thirdparty/phpMyAdmin/

File not found.

yum install kloxomr-thirdparty-phpmyadmin

安装 Kloxo-MR 7.0.0.b 后发现在面板中点击20150425021410

Url地址 – /thirdparty/phpMyAdmin/

File not found.

打开后找不到文件:

20150425020556

之后在服务组件中也看不到有phpMyAdmin 的信息。

sftp上服务器上的 Kloxo下也确实没有.  也许thirdparty就是要自己装把, 那么就装吧.

如下:

yum list kloxomr-thirdparty*

| 列出以 kloxomr-thirdparty 打头 记得后面有个星号.

kloxomr-thirdparty-phpmyadmin
kloxomr-thirdparty-jcterm
kloxomr-thirdparty-sshterm-applet

,找到全部的kloxomr第三方插件, 然后安装 phpMyAdmin

yum install kloxomr-thirdparty-phpmyadmin

20150425024041

如此,已经OK!

Google搜索技巧

搜索引擎在今天其实就是使用网络的基本功,也是在线一切工作的得力助手。
而很多人依然不知道如何使用搜索引擎查找想要的东西,经常会有人打电话问你帮他找些什么。
所以把这个谷歌文档发给他就可以了。

了解一些帮助您轻松通过 Google 找到信息的提示和技巧。

提示 1:使用简单的搜索字词

无论要搜索什么,都请先用简单的字词进行搜索,例如最近的机场在哪里?您随时可以根据需要添加一些描述性字词。

如果您要查找特定地点的某个场所或商品,可添加该地点名称。例如,南京面包店

提示 2:通过语音搜索

不想打字?点击 Google 应用或 Chrome 搜索框中的麦克风图标 ,通过语音执行搜索

提示 3:认真选择措辞

在确定输入搜索框中的字词时,尽量选择要查找的网站上可能会出现的字词。例如,不要使用我的头很痛,而要使用头痛,因为医学网站上往往会使用后者。

提示 4:不用担心输入方面的琐事

  • 拼写。 无论您的拼写是否正确,Google 的拼写检查工具都会自动使用给定字词的最常用拼写形式。
  • 大写。 搜索 QQqq 所得到的结果是一样的。

提示 5:查找快速解答

对于您进行的许多搜索,Google 都会替您完成相关工作,并会在您输入搜索字词后在搜索结果页上显示相关解答。有些功能(例如查询与球队有关的信息)并非在所有地区都提供。

  • 天气:搜索天气可查看您所在地点的天气信息,如果在“天气”后加上城市名(例如天气北京),则可查看相应城市的天气信息。
  • 字典:在任意字词前加上 define 即可查询其定义。
  • 计算:输入数学公式(例如 3*9123)或求解复杂的图形公式。
  • 单位换算:输入任何换算内容,例如 3 美元兑换欧元
  • 体育:搜索球队的名称,即可查看相关赛程和比赛得分等信息。
  • 快讯:搜索名人、地点、电影或歌曲的名称可看到相关重要信息。

搜索中的标点、符号和运算符

您可以使用特殊的字符和字词来获取更具体的搜索结果。Google 会忽略大部分的标点符号(以下示例除外)。例如,搜索字词狗! 会被 Google 视为

Google 搜索可以识别的标点和符号

即使以下符号均受支持,在您的搜索中加入这些符号也并不一定会改善搜索结果。如果我们认为该标点不会为您提供更好的结果,则会显示出不含标点的搜索字词所对应的建议结果。

请注意:在使用符号进行搜索时,请勿在符号和搜索字词之间添加空格。我们可以识别-狗中的符号,但无法识别- 狗中的符号。

符号 用途
+ 搜索 Google+ 网页或血型 示例:+Chrome 和 AB+
@ 查找社交标记 示例:@agoogler
$ 查找价格
示例:尼康 $400
# 查找热门主题标签以搜索热门话题 示例:#throwbackthursday
- 移除字词在某个字词或网站之前添加一个短横可排除所有包含该字词或网站的搜索结果。在搜索有多种含义的字词(例如“汽车品牌捷豹”和“动物捷豹”)时,这种方法尤为实用。

示例:捷豹速度 -汽车熊猫 -site:wikipedia.org

连字如果多个字词以短横相连,Google 便会知道这些字词是紧密关联的。

示例:twelve-year-old dog

_ 用于连接两个字词,例如 quick_sort。 您会在搜索结果中发现,这对字词要么组成一个字词 (quicksort),要么由下划线相连 (quick_sort)。
" 如果您将字词或词组置于引号中,则搜索结果中将仅显示以下网页:包含引号中的字词且字词顺序也与引号中相同。 请注意:请仅在需要搜索某个精确字词或词组时使用这种搜索方式,不然,可能会错误地排除掉很多有用的搜索结果。 示例:"想象一下所有人"
* 在搜索中添加一个星号,以表示任何未知或不确定的字词。与引号结合使用,可以查找具体词组的不同变体,或记住词组中间的字词。 示例:"省*就是赚*"
.. 使用不含空格的两个半角句号 (..) 隔开多个数字,即可查看日期、价格和尺寸等方面的数值在指定范围内的搜索结果。 示例:相机 $50..$100

使用搜索运算符缩小搜索结果范围

搜索运算符是可添加到搜索字词中以帮助缩小搜索结果范围的字词。不必担心,您不一定要记住每个运算符,因为您也可以使用“高级搜索”页面来进行这种搜索。

请注意:使用运算符进行搜索时,请勿在运算符和搜索字词之间添加空格。搜索 site:nytimes.com 可以获取相关搜索结果,而搜索 site: nytimes.com 则是行不通的。

运算符 用途
site: 仅从特定网站或网域获得搜索结果。例如,您可以查找 NBC 网站或任何 .gov 网站上所有提到“奥运”的内容。 示例:olympics site:nbc.com 和 olympics site:.gov
link: 查找链接到某个特定网页的页面。例如,您可以查找链接到 google.com.hk 的所有页面。 示例:link:google.com.hk
related: 查找与您已浏览过的网址类似的网站。当您搜索与 time.com 相关的网站时,会找到您可能感兴趣的其他新闻出版物网站。 示例:related:time.com
OR 如果您想搜索可能只包含多个搜索字词中某一个的页面,可以在这些字词之间加上 OR(大写)。如果不加 OR,您的搜索结果中通常只会显示与这些字词都匹配的页面。 示例:世界杯举办地2014年OR 2018年
info: 获取某网址的相关信息,包括网页的缓存版本、相似网页和链接至该网站的网页。 示例:info:google.com
cache: 查看 Google 上次抓取网站时网页的外观。 示例:cache:washington.edu

继续阅读“Google搜索技巧”

VPS下对mysql内存性能的优化

VPS的内存对性能至关重要,所以很有必要优化一下。

看了几篇针对vps小内存优化的文章,于是自己也动手参照优化下自己的mysql。

修改过调整好的 my.cnf ,service mysqld restart 启动时报错。

查看log,发现 skip-innodb / skip-bdb / skip-locking,这几个参数有问题。

 

继续学习,查资料,得知 使用的参数都是老版本的参数,mysql5.1对应的为:

skip-innodb  –>  loose-skip-innodb

skip-locking  –> skip-external-locking

skip-bdb (已经废除了skip-bdb这个参数!)

 

配置文件: /etc/my.cnf

# low memory stuff – Mr.Tang
# Tue May 26 22:23:15 CST 2015

[mysqld]

loose-skip-innodb
skip-external-locking
skip-host-cache
skip-name-resolve

character_set_server = utf8
default-storage-engine = myisam

key_buffer_size = 256M
key_buffer = 256K
max_allowed_packet = 1M
myisam_sort_buffer_size = 8M
net_buffer_length = 128K
query_cache_size= 16M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
sort_buffer_size = 1M
table_cache = 4M
table_open_cache = 16M
thread_cache_size = 8M
thread_stack = 131072

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
#safe-updates

[isamchk]
key_buffer = 8M
sort_buffer_size = 8M

[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

优化WordPress,解决加载慢,等待google引用地址超时问题

近几个月发现空间经常很慢,特别是WordPress响应非常迟钝,但一直懒得动它。 前几天实在受不了,正巧看到一个特价的vps,就用paypal支付了$,买了一个. 搞好了系统,配置好环境,就在准备迁移WordPress数据的时候,偶然看到一个文章,说近来几个月很多人的WordPress都是变的很慢。 查了查相关文章,跟google被墙有关,原因是wp的字体加载的都是 在google托管的,还有些js,css脚本等等,比如:

<link href='http://fonts.googleapis.com/css?family=Open+Sans:300,400,600&subset=latin,latin-ext' rel='stylesheet'>

<script src="http://html5shim.googlecode.com/svn/trunk/html5.js">

<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js?ver=3.4.2'></script>

这样 googleapis.com,googlecode.com 无法联通,自然相关引用的字体,脚本也都无法加载,只有等待主机超时, 所以WordPress都变的很慢。 知道问题所在就处理它。

 [ 只解决最影响加载速度的字体就可以了 ]

1。不使用google字体

编辑主题的 functions.php文件,在末尾添加以下代码:
//禁用Open Sans
class Disable_Google_Fonts {
public function __construct() {
add_filter( ‘gettext_with_context’, array( $this, ‘disable_open_sans’             ), 888, 4 );
}
public function disable_open_sans( $translations, $text, $context, $domain ) {
if ( ‘Open Sans font: on or off’ == $context && ‘on’ == $text ) {
$translations = ‘off’;
}
return $translations;
}
}
$disable_google_fonts = new Disable_Google_Fonts;

这里提供了由360网站卫士CDN驱动的常用前端公共库以及和谐使用Google公共库&字体库的调用方法

下面的方法2,3是使用 – 360网站卫士常用前端公共库CDN服务 替换 google的对应引用地址。

2。手动修改替换引用地址

打开wordpress文件: wp-includes/script-loader.php

搜: fonts.googleapis.com

替换:fonts.googleapis.com替换为 fonts.useso.com ,保存文件,发现问题解决了。

原理就是用360来加速google字体。

速度很好,360的加速很快。

3。使用插件

如何通过第三方Wordpress字体转换插件继续使用Google字体库? (感谢来自淘宝的soulteary童鞋开发了这个插件) 插件说明地址:http://www.soulteary.com/2014/06/08/replace-google-fonts.html 插件下载地址:http://www.soulteary.com/wp-content/uploads/2014/06/Replace-Google-Fonts.zip

—- P.S. 这样暂时就不用站点迁移了. 差点误会了服务商.

Json.NET 反序列化 多层次 泛型 复杂对象 json(如List)到数据实体对象

做了一天有关于JSON的工作,解析为JSON难度到不大,用.Net中微软自己的方法也很好用。

多层次泛型复杂对象(不是简单的 List<T> 而是  List<<List<T>>>)到数据实体对象,花了大半天时间从下午到晚上,一直研究到快凌晨。。。

最后还是放弃微软的方法。使用了 Json.NET 的 Newtonsoft.Json.dll 来反序列化。

 

随便推荐一个网站: 在线JSON校验格式化工具(K JSON) – json解析,json格式化,json 在线校验  http://www.kjson.com/

可以把要反解析的json放进去效验一下,避免错误格式,比如我今天遇到几次收到的 json 压根就是格式不正确的json … 非常耽误时间

 

下面给个例子供参考:

( 例子是在Handler1.ashx中做的,首先引用 “using Newtonsoft.Json;”)

using System;
using System.Collections.Generic;
using System.Web;
using System.IO;
using Newtonsoft.Json;

namespace WebApp1
{
    /// <summary>
    /// Handler1 的摘要说明
    /// </summary>
    public class Handler1 : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            string strJson = @"{
                                    'success': true,
                                    'Object': {
                                        'ID': -1,
                                        'MoveID': 'D09-242',
                                        'EX_Unit': 00,
                                        'In_Unit': 00,
                                        'Remark': 'OK',
                                        'Detail': [
                                            {
                                                'ID': 1,
                                                'M_ID': null,
                                                'DVID': '11',
                                                'DVName': 'aa0',
                                                'DVType': null
                                            },
                                            {
                                                'ID': 2,
                                                'M_ID': null,
                                                'DVID': '22',
                                                'DVName': 'aa1',
                                                'DVType': null
                                            },
                                            {
                                                'ID': 3,
                                                'M_ID': null,
                                                'DVID': '33',
                                                'DVName': 'aa2',
                                                'DVType': null
                                            }
                                        ]
                                    },
                                    'msg': '成功'
                                }";
            ///大{}内 JSONObject 数据, 最外层
            JSONObject<MoveInfo<MoveDetailInfo>> obj = Newtonsoft.Json.JsonConvert.DeserializeObject<JSONObject<MoveInfo<MoveDetailInfo>>>(strJson);
            string msg = obj.msg;
            string success = obj.success.ToString();

            ///'Object'是实体对象类"MoveInfo"的实体类的数据
            MoveInfo<MoveDetailInfo> info = obj.Object;
            int Mv_id1 = info.ID;   //可以直接赋值给MoveInfo的对象获取到值
            int Mv_id2 = obj.Object.ID; //还可以用上层的Object.ID获取到值

            ///info.Detail 或 obj.Object.Detail 都是实体对象类"MoveDetailInfo"的实体类的数据
            string DVName1 = "";
            string DVName2 = "";
            string DVName3 = "";

            DVName1 = obj.Object.Detail[0].DVName;      //方法1: 从最上次对象实体中取子属性

            foreach(MoveDetailInfo mvinfo in info.Detail)
                DVName2 += mvinfo.DVName;       //方法2: 迭代上层 info.Detail 对象"MoveDetailInfo"获取属性

            MoveDetailInfo dvinfo =  info.Detail[0];
            DVName3 = dvinfo.DVName;        //方法3: 再赋值给MoveDetailInfo对象类后获取

            context.Response.ContentType = "text/plain";
            context.Response.Write(string.Format("0;{0}\r1:{1};\r2:{2};", DVName1, DVName2, DVName3));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

    public class JSONObject<T>
    {
        private bool _success;
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool success
        {
            get { return _success; }
            set { _success = value; }
        }

        private T _Object;
        /// <summary>
        /// 业务实体对象
        /// </summary>
        public T Object
        {
            get { return _Object; }
            set { _Object = value; }
        }

        private string _msg;
        /// <summary>
        /// 消息
        /// </summary>
        public string msg
        {
            get { return _msg; }
            set { _msg = value; }
        }
    }

    /// <summary>
    /// MoveInfo 调拨单
    /// </summary>
    public class MoveInfo<T>
    {
        private int _ID;
        public int ID
        {
            get { return _ID; }
            set { _ID = value; }
        }

        private string _MoveID;
        public string MoveID
        {
            get { return _MoveID; }
            set { _MoveID = value; }
        }

        private int _EX_Unit;
        public int EX_Unit
        {
            get { return _EX_Unit; }
            set { _EX_Unit = value; }
        }

        private int _In_Unit;
        public int In_Unit
        {
            get { return _In_Unit; }
            set { _In_Unit = value; }
        }

        private List<MoveDetailInfo> _Detail;
        public List<MoveDetailInfo> Detail
        {
            get { return _Detail; }
            set { _Detail = value; }
        }
    }

    /// <summary>
    /// 调拨明细信息
    /// </summary>
    public class MoveDetailInfo
    {
        private int _ID;
        public int ID
        {
            get { return _ID; }
            set { _ID = value; }
        }

        private string _M_ID;
        public string M_ID
        {
            get { return _M_ID; }
            set { _M_ID = value; }
        }

        private string _DVID;
        public string DVID
        {
            get { return _DVID; }
            set { _DVID = value; }
        }

        private string _DVName;
        public string DVName
        {
            get { return _DVName; }
            set { _DVName = value; }
        }

        private string _DVType;
        public string DVType
        {
            get { return _DVType; }
            set { _DVType = value; }
        }
    }
}

 

参考文章 :

.net泛型在序列化、反序列化JSON数据中的应用  http://www.cnblogs.com/jdmei520/archive/2009/09/19/1569600.html

C# 将javascript的JSON反序列化为数组,泛型List,对象  –  http://hi.baidu.com/jiang_yy_jiang/item/c32aff05bcce12ca915718e8

 

 

email2ascii — 将EMail地址转换为Ascii

今天看到一个很好的隐藏页面邮件地址的例子:

通过将电子邮件地址转码为Ascii编码,在页面完成一种简单的电子邮件地址保护,减少你收到垃圾邮件的概率。

 

HTML:
<a href="mailto:&#100;&#105;&#115;&#116;&#114;&#111;&#64;&#100;&#105;&#115;&#116;&#114;&#111;&#119;&#97;&#116;&#99;&#104;&#46;&#99;&#111;&#109;">Ladislav Bodnar</a>

鼠标移动到连接, 页面状态栏显示的是:

mailto:distro@distrowatch.com

 

完整代码,请查看:  EMail 地址转 Ascii — 将EMail地址转换为Ascii

http://bohu.net/t/email2ascii.php

 

PHP:

<?php
	$result=array();
	for($i=0,$l=mb_strlen($email,'utf-8');$i<$l;++$i){
			$result[]="&amp;#".uniord(mb_substr($email,$i,1,'utf-8'));
	}
	echo "<pre>".join(";",$result).";</pre>";
?>

JavaScript:

<script type="text/javascript">
	var s = "<?php echo $email;?>";
	var as = "";
	for(var a = 0; a<s.length; a++){
			 as += "&amp;#"+s.charCodeAt(a)+";";
	 }
	document.write("<pre>"+as+"</pre>");
</script>

 

完整PHP代码:

email2ascii.txt — 右键另存下载

 

选择 PHP Debugger 调试器

选择哪个 PHP 调试器?

[转载请注明出处:http://bohu.net/blog/?p=8854]

PHP 并没有内部调试器。但是可以使用外部调试器。» Zend    IDE 就是其中之一,它包含一个调试器。

也有一些免费的调试器,比如在     » http://www.php-debugger.com/dbg/ 上的 DBG,» Advanced    PHP Debugger(APD,注:似乎已经停止更新)或者 » Xdebug

Zend Studio

优点:支持全php版本,集成度高,兼容性好。
缺点:程序庞大,需付费的软件。

使用Zend Technologies开发的 Zend Studio ,因为它是专业开发人员PHP整个开发周期中唯一的集成开发环境 (Integrated Development Environment,IDE),它包括了PHP所有必须的开发部件。通过一整套编辑、调试、分析、优化和数据库工具,Zend Studio 加速开发周期,并简化复杂的应用方案。

它支持PHP语法加亮显示,支持语法自动填充功能,支持书签功能,支持语法自动缩排和代码复制功能,内置一个强大的PHP代码调试工具,支持本地和远程两种调试模式,支持多种高级调试功能。也支持HTML和js标签,但只对PHP语言提供调试支持。

因为是同一个公司的产品,所以它对的Zend Framework方面的支持比其他软件好。

Zend Studio5.5系列后,官方推出利用了Eclipse平台,基于PDT的Zend Studio for Eclipse 6.0,之后的版本也都构建于Eclipse。

Zend Studio是屡获大奖的专业 PHP 集成开发环境,具备功能强大的专业编辑工具和调试工具,
Zend Studio可以在Linux、Windows、Mac OS X上运行。 最大遗憾是Zend的产品是付费的。

Xdebug

优点:支持php4.3 – 5.5版本,支持zend引擎,免费。
缺点:Xdebug 不能和 Zend Optimizer或任何其他处理 PHP 的内组件 (DBG、 APD、 ioncube 等) 的扩展。这是因为这些模块有兼容性问题。

推荐安装扩展插件 XDEBUG EXTENSION FOR PHP   –  文档:http://xdebug.org/docs/all

Windows下安装预编译的  模块,有几个预编译的模块,用于 Windows,他们是所有的非调试版本的 PHP。你可以得到那些在下载页。按照这些说明来安装 Xdebug。

安装可以在其网站使用web向导模式,帮助你安装: http://xdebug.org/wizard.php

一下是按照方法:

1. 在cmd下,php -i >> c:\\phpinfo.txt

信息保存在 ,然后拷贝phpinfo.txt中内容至http://xdebug.org/wizard.php的文本框内,

然后点击 ‘Analyse my phpinfo() output’ 按钮,将会分析你的phpinfo,然后显示出分析的php配置,以及你要在php.ini中添加的内容:

你对应下载所提示的dll文件,放在第2步所对应的你的php安装目录中,第3步在php.in中添加一行:zend_extension = "C:\Program Files\iis express\PHP\v5.3\ext\php_xdebug-2.2.3-5.3-vc9-nts.dll"

然后查看phpinfo() 或者cmd php -i 检查是否已经加载了xdebug

phpdbg

优点:PHP官方推介的。从 PHP5.6 phpdbg 将以SAPI 模块包含在 PHP内,实现交互式调试器。
缺点:必须版本 > PHP 5.4.0 以及最新版本。易用性暂不明确。

PHP官方网站里显示:

PHP 5.6.0 alpha 最后终版附带了一个交互式调试器名为phpdbg。
phpdbg 项目页面: http://phpdbg.com/

Phpdbg 以 SAPI 模块实现的而不会影响代码的性能或功能可以 excert 完全控制环境。

phpdbg 的目标是一个轻量、 功能强大、 易于使用的调试平台,自 PHP5.4 +

功能

  • Stepthrough 调试
  • 类方法、 函数、 File:Line、 地址操作码) 的灵活断点
  • 方便地访问到 PHP 的内置 eval()
  • 方便地访问到当前正在执行的代码
  • 用户态的 API
  • SAPI 不可知论-轻松地集成
  • PHP 配置文件支持
  • JIT 超级全局变量-设置您自己!!
  • 可选 readline 支持-终端操作舒适
  • 远程调试支持-捆绑 Java GUI
  • 容易操作-请参阅帮助:)

详细文档查看: http://phpdbg.com/docs

Phpdbg 还有一个远程调试时所使用的Java GUI客户端程序:

希望PHP 5.6发布后看看Phpdbg的功效如何!

JS中转义字符在replace中的转码替换

JS特殊符号的replace转码替换方法.

里面转的不全, 比如&amp; 很多没有加, 自己添加把.

关于转义字符先关的网址:

 

<script>
        window.onload = function () {
            var xxxx = "&quot;&lt;&gt;&amp;测试代码";
            alert(html_decode(xxxx));
        }

function html_encode(str)   
{   
  var s = "";   
  if (str.length == 0) return "";   
  s = str.replace(/&/g, "&gt;");   
  s = s.replace(/</g, "&lt;");   
  s = s.replace(/>/g, "&gt;");   
  s = s.replace(/ /g, "&nbsp;");   
  s = s.replace(/\'/g, "&#39;");   
  s = s.replace(/\"/g, "&quot;");   
  s = s.replace(/\n/g, "<br>");   
  return s;   
}   

function html_decode(str)   
{   
  var s = "";   
  if (str.length == 0) return "";   
  s = str.replace(/&gt;/g, "&");   
  s = s.replace(/&lt;/g, "<");   
  s = s.replace(/&gt;/g, ">");   
  s = s.replace(/&nbsp;/g, " ");   
  s = s.replace(/&#39;/g, "\'");   
  s = s.replace(/&quot;/g, "\"");   
  s = s.replace(/<br>/g, "\n");   
  return s;   
}   

</script>