Xydw Dot Com

Archive for the ‘Codes & Scripts’ Category

[php]vsprintf VS preg_replace

I want to formart a simple string in PHP. There are two ways to do this. One is vsprintf and another preg_replace. But who is faster?  I have tested both of them. I find that vsprintf run more faster while can parse string in many formart.  So why not use vsprintf to replcae preg_replace if [...]

an idea to fix innerHTML to table in IE (firefox)

I like to use innerHTML . It is fast and easy to use. But there are some problems under different browsers, such as innerHTML can’t use to insert to table elements under IE.
I have search on google with this issue. There are no good idea to fix innerHTML to table. Someone use Jquery append to [...]

PHP 正则匹配 特殊元字符

字符 描述
\
将下一个字符标记为一个特殊字符、或一个原义字符、或一个后向引用、或一个八进制转义符。例如,’n’ 匹配字符 “n”。’\n’ 匹配一个换行符。序列 ‘\’ 匹配 “” 而 “\(” 则匹配 “(“。
^
匹配输入字符串的开始位置。如果设置了 RegExp 对象的 Multiline 属性,^ 也匹配 ‘\n’ 或 ‘\r’ 之后的位置。
$
匹配输入字符串的结束位置。如果设置了RegExp 对象的 Multiline 属性,$ 也匹配 ‘\n’ 或 ‘\r’ 之前的位置。
*
匹配前面的子表达式零次或多次。例如,zo* 能匹配 “z” 以及 “zoo”。 * 等价于{0,}。
+ 匹配前面的子表达式一次或多次。例如,’zo+’ 能匹配 “zo” 以及 “zoo”,但不能匹配 “z”。+ 等价于 {1,}。
?
匹配前面的子表达式零次或一次。例如,”do(es)?” 可以匹配 “do” 或 “does” 中的”do” 。? 等价于 {0,1}。
{n}
n 是一个非负整数。匹配确定的 n 次。例如,’o{2}’ [...]

tow php code cost double memory

I got a error to use a 2M string in php code.But the php settings memory limit is 8M.
Fatal error: Allowed memory size of **** bytes exhausted (tried to allocate *** bytes)
Then I check the php code, I find there are some codes cost more memory.
$tmp = “string”.$tmp.”string”;
I change those codes to:
$tmp = “string”.$tmp;
$tmp .= [...]

PHP function to get google PR

<?php
// 3/20/2008 – Updated by Roger Collins (http://www.rogercollins.com/)
// to remove graphing step
//PageRank Lookup v1.1 by HM2K (update: 31/01/07)
//based on an alogoritham found here: http://pagerank.gamesaga.net/
//settings – host and user agent
$googlehost=‘toolbarqueries.google.com’;
$googleua=‘Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5′;
echo getpr(“http://www.xydw.com”);
//convert a string to a 32-bit integer
function StrToNum($Str, $Check, $Magic) {
$Int32Unit = 4294967296; // 2^32
$length = strlen($Str);
for [...]

Javascript scrollbar

http://www.n-son.com/scripts/jsScrolling/jsScrollbar.html
it is a very good and useful scripts.

Preparation
Before initializing the scrollbar, you must create a jsScroller object. So if you haven’t, follow the previous tutorial and find out how!
First thing is the HTML:
<div id=”Scrollbar-Container”>
<div class=”Scrollbar-Up”></div>
<div class=”Scrollbar-Down”></div>
<div class=”Scrollbar-Track”>
<div class=”Scrollbar-Handle”></div>
</div>
</div>
Again, “Scrollbar-Container” can be change to anything you want, you just need to be able reference this element [...]

Modify wordpress themes special links

In some wordpress themes may be you would find some links can not be modified, even if you can not find where there are. How to modify them?Follow me…
First you find the file which you think those links will be.
Then try search by some tools such as Notes, ZDE.
If you do not get [...]