in

SDT Community Server

SDT Forums, Blogs, Photos server.

wego

February 2007 - Posts

  • PHP 日期加减有点特别

     感觉比较 "傻瓜"

     

    echo strtotime("+1 day"), "\n";

    echo strtotime("+1 week"), "\n";

    echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";

    echo strtotime("next Thursday"), "\n";

    echo strtotime("last Monday"), "\n";

     

    而 strtotime("-0.5 year") 是得不到半年前的日期的, 要改用 strtotime("-6 month")

    只能接受整数范围.  又有点遗憾 ..


     

  • Oracle 正规应用

     

     

    偶尔发现 Oracle 中的 Replace 函数有个不足.

    :  select  replace (upper('Test Regexp'),upper('test'),'hello') from dual  就取不到想要结果 : hello Regexp 而是 hello REGEXP.

     

    若用其正规函数则可实现:  select  REGEXP_REPLACE ('Test Regexp', 'test', 'hello', 1, 0, 'i') from dual

     

    此外, 正规函数还有好多功能强大灵活的地方,

    1) select  REGEXP_REPLACE ('as  dfg   r', ' [ ]*', ' ', 1, 0, 'i') from dual  -- 可将连断N个空格置成一个.

     

    2) select '1' from dual where REGEXP_LIKE ('hi sDt,2007 year', '[^[:alpha:]]SDT[^[:alpha:]]','i'); 

        select '1' from dual where REGEXP_LIKE (' hi sDts,2007 year', '[^[:alpha:]]SDT[^[:alpha:]]','i'); 

        -- 查找是否存在指定单词SDT (如果用平时的 like 来实现则语句会很长很长)

Copyright SDT, 2006-2009. All rights reserved.