yeah

搜索

计数器

62863

链接

用MySQL内置函数转换ip地址和数字

Jan 07, 2010 06:42:01 PM | Comments(2) | Category:PHP学习 | Tags:

用MySQL内置函数转换ip地址和数字

利用两个内置函数
inet_aton:将ip地址转换成数字型
inet_ntoa:将数字型转换成ip地址


Tags -

createtextrange createrange有什么区别

Jan 06, 2010 07:11:24 PM | Comments(4) | Category:PHP学习 | Tags:

对象或元素不同,虽然都是返回TextRange。例如:
var r=document.body.createTextRange()
var r=document.createRange()
createTextRange可以对body、TEXTAREA、BUTTON创建TextRange

js为选中的文本加链接

Jan 06, 2010 07:02:00 PM | Comments(1) | Category:PHP学习 | Tags:

selection是文档中被选择的所有对象   
createRange()是将创建一个textRange()对象,就是文档中被选择的所有文本都放到这个对象里了   
pasteHTML()将被选中的文本清空,然后将给定的HTML串粘贴进来

例子:
<script type="text/javascript">
        function addLink(){
           var oRange = document.selection.createRange();
           if(oRange.text!=''){
              var oUrl = window.prompt('链接网址...','http://www.163.com/');
              var oHtml = '<a href=' oUrl ' target=_blank>' oRange.text '</a>';
              alert(oHtml);
              oRange.pasteHTML(oHtml);
           }else{
              window.alert('您没有选择加链接的文字!');
           }
        }
</Script>

<input type="button" value="添加链接" onclick="addLink();" >
<area>hehe</area>


Tags -

运用JS将搜索的关键字高亮显示

Jan 06, 2010 06:56:37 PM | Comments(3) | Category:PHP学习 | Tags:

<script type="text/javascript">
function highlight(key) {
    var key = key.split('|'); //用"|"分割关键字
    for (var i=0; i<key.length; i ) {
        //为 body 建立 TextRange 对象。使用此 TextRange 对象可以检索和修改 boy 内的文本。
        var rng = document.body.createTextRange();
        while (rng.findText(key[i]))
              //pasteHTML()将被选中的文本清空,然后将给定的HTML串粘贴进来
              rng.pasteHTML('<div style="border:1 solid red;display:inline"><a href="http://dhost.info/yeah/admin.php#" title=' rng.text '>' rng.text '</a></div>');
    }
}
highlight('文章|关键|功能')
</script>

curl 抓取页面时的 cookie 问题

Jan 04, 2010 08:28:55 PM | Comments(9) | Category:PHP学习 | Tags:

使用 PHP curl 抓取页面时,可以设置 cookie 保存的文件,示例代码:

 

<?php
$cookie_path = 'cookie.txt';
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_path);
//....
?>

特别需要注意的是,在完成抓取之后,需要把 cookie 文件删除,否则下次抓取时会自动使用原有的 cookie 数据,从而导致一些预想不到的错误

控制器基类做访问过滤[总结]

Jan 03, 2010 08:35:17 PM | Comments(1) | Category:yii | Tags:

写基类的beforeAction函数:

 

protected function beforeAction($action)
    {
        $route=$this->id.'/'.$action->id;
        if(!in_array($route,array('site/login','site/error','site/logout')))
        {
            if(Yii::app()->user->isGuest)
                Yii::app()->user->loginRequired();
            else
                throw new CHttpException(403,'You are not authorized to perform this operation.');
        }
        return true;
    }
 

框架扩展:

 

// preloading 'log' component       
'preload'=>array('log','access'),
----------------------------------------------       
// application components       
'components'=>array(               
    'log'=>array(                       
        'class'=>'CLogRouter',                       
        'routes'=>array(                               
            array(                                       
                'class'=>'CFileLogRoute',                                       
                'levels'=>'error,warning',
            ),                       
        ),               
    ),               
    'access'=>array(                       
        'class'=>'application.components.EAccess',               
    ),
//other code
)

 

<?php
class EAccess extends CApplicationComponent {       
     private $_routes=array();       
/**         * Initializes this application component.         * This method is required by the IApplicationComponent interface.         */      
    public function init()        {  
         parent::init();               
        //开始请求时,代码               
        if(!Yii::app()->user->isGuest){                       
            Yii::app()->attachEventHandler('onbeginRequest',array($this,'myaccess'));
         }else{  
        }       
    }       
/**         * 代码         */  
    public function myaccess()        {  
              //hello world       
     }       
}

用MySQL内置函数转换ip地址和数字

Dec 31, 2009 03:40:19 AM | Comments(0) | Category:PHP学习 | Tags:

        用MySQL内置函数转换ip地址和数字

  利用两个内置函数

  inet_aton:将ip地址转换成数字型

  inet_ntoa:将数字型转换成ip地址

  充分利用mysql内置的format函数

  尤其是在处理字符格式的时候,例如将12345转换成12,345这样的,只要用:format(12345,0)即可,如果用format(12345,2)则显示的是12,345.00了...

php调用.net webservice 验证,调用难题

Dec 25, 2009 10:22:04 PM | Comments(1) | Category:PHP学习 | Tags:

1.soapHeader的构造

<soap:Header>
    <CredentialSoapHeader xmlns="http://YouXi.com.cn/">
      <ViaStr>string</ViaStr>
      <Md5Text>string</Md5Text>
    </CredentialSoapHeader>
</soap:Header>

构造代码:

 

 2.在调用.net webservice时,用一个参数 parameters 为要传入的参数 

<?php
$res = $client->__soapCall('ExistsUserByName', array('parameters'=>array('strUserName'=>$username)));
?>

<?php
$value = array(
    'ViaStr' => 'abc123',
    'Md5Text' => md5('abc123987654321')
);
$header = new SOAPHeader('命名空间', 'CredentialSoapHeader', $value, false);
?>

php对象<=>数组互转

Dec 25, 2009 06:19:57 PM | Comments(0) | Category:PHP学习 | Tags:

1.对象=>数组

(1).强制转换

 

原对象为
<?php
stdClass Object   
(   
    [name] => main   
    [text] =>   
    [parrent] =>   
    [content] =>   
    [props] => Array   
        (   
        )   
 
    [inner] => Array   
        (   
        )   
 
    [level] => 0   
)
?>
<?php
$arr = (array)$obj;
?>
强制转换后的数组
<?php
Array   
(   
    [name] => main   
    [text] =>   
    [parrent] =>   
    [content] =>   
    [props] => Array   
        (   
        )   
 
    [inner] => Array   
        (   
        )   
 
    [level] => 0   
) 
?>

(2).用内置函数get_object_vars();

 2.数组=>对象

<?php
$array = get_object_vars( $object );
?>
原对象:
<?php
class foo {       
     
    private $a;       
     
    public $b = 1;       
     
    public $c;       
     
    private $d;       
     
    static $e;       
     
}           
$test = new foo;             
var_dump(get_object_vars($test))
?>
结果为:
<?php
array(2) {     
    ["b"]=>  int(1)             
    ["c"]=>  NULL           
} 
?>

 

(1).用stdClass转换数组为对象

 

数组
<?php
$arr = array();   
$arr['a'] = 1;   
$arr['b'] = 2;   
$arr['c'] = 3
?>
用stdClass转换后:
<?php
$object = new StdClass;   
$object->a = 1;   
$object->b = 2;   
$object->c = 3
?>

 (2).ArrayObject,可以直接将数组转化为对象

 

<?php
$array = array('1' => 'one',   
               '2' => 'two',   
               '3' => 'three');   
$arrayobject = new ArrayObject($array);   
var_dump($arrayobject)
?>
<?php
object(ArrayObject)#1 (3) {   
  [1]=>   
  string(3) "one" 
  [2]=>   
  string(3) "two" 
  [3]=>   
  string(5) "three" 
} 
?>

 

 

设置文件的修改时间

Dec 24, 2009 01:45:13 AM | Comments(0) | Category:PHP学习 | Tags:

 

bool touch ( string $filename [, int $time= time() [, int $atime ]] )

<?php
if (touch($FileName)) {
    echo "$FileName modification time has been changed to present time";
} else {
    echo "Sorry, could not change modification time of $FileName";
}
?>

<?php
/*
 * This is the touch time, we'll set it to one hour
 * in the past.
 */

$time = time() - 3600;

/* Touch the file */
if(!touch('some_file.txt', $time))
{
    echo 'Whoops, something went wrong...';
}
else
{
    echo 'Touched file with success';
}
?>