• 2264bf3fb63a219d674a6463cadb98dd.png
     

    一般說來,如果要做搜尋,通常都會把關鍵字標記起來。不過如果做多個關鍵字查詢時,還要把文章中出現多個字也標記就會比較麻煩了。

    例如,要把 font color 標記起來,如果原文是 The font color is red。若你單純的 replace 兩次,標記紅色字,就會變成

    第一次 replace font

    The <font color='red'>font</font> color is red

    第二次 replace color

    The <font <font color='red'>color</font>='red'>font</font> <font color='red'>color</font> is red

    這樣就會亂掉了。研究了一下,直接給大家看我的作法,如果有更好的建議歡迎提出喔!

    function MarkKeywords($text, $keys)
    {
        $text = htmlspecialchars($text);
         
        $patterns = '/('. implode('|', $keys) .')/i';
        $ntext = preg_replace_callback(
                $patterns,
                create_function(
                    '$matches',
                    'return "<font color=\"red\">$matches[0]</font>";'
                ),
                $text
            );
     
        return $ntext;
    }
     

    使用方式如下:

    $text = "The font color is red";
     
    $keys[] = 'font';
    $keys[] = 'color';
     
    $marked = MarkKeywords($text, $keys);
     
    echo $marked;
     

    這樣一來,不但不分大小寫,而且不會處理錯誤!提供給大家囉!

    * 有朋友提出更好的做法。也 PO 在下面喔!如果不對比對的文字另外處理的話,以下的作法就可以達到要求了!

    function MarkKeywords($text, $keys)
    {
        $text = htmlspecialchars($text);
        $patterns = '/('. implode('|', $keys) .')/i';
        $replacements = '<font color=red>${0}</font>';
        return preg_replace($patterns, $replacements, $text);
    }
    PHP | 5066 觀看 | 2013-09-03 | 標籤: php, keyword, mark | Kuann Hung 上傳
  • 73e39f11bbe5e86d37181a790230e229.jpg
     

    為了要支援 facebook 的 open graph,所以在 <head> 中都會加上相對應的 og tag。

    但如果是讓 User 自己撰寫文章的情況,則指定 og:image 就會比較麻煩。以下提供一個 function 可以抓出文章中的 image

    function GetImgFromHTML($html) 
    {
        if (stripos($html, '<img') !== false) 
        {
            $imgsrc_regex = '#<\s*img [^\>]*src\s*=\s*(["\'])(.*?)\1#im';
            preg_match($imgsrc_regex, $html, $matches);
            unset($imgsrc_regex);
            unset($html);
            if (is_array($matches) && !empty($matches)) 
                return str_replace(' ', '%20', trim($matches[2]));
            else
                return false;
             
        } else
            return false;
    }
     

    只要回傳值不是 false 就是文章中第一個出現的 image tag 了!

     
    •  
    PHP | 4458 觀看 | 2013-09-03 | 標籤: imagemagick, html, tag | Kuann Hung 上傳
  • 0e796005547d08fa083bff166a0c95e4.png
    # yum install php php-pear php-devel
    # yum install gcc make
    # pecl download json
    # pear install json-1.2.1.tgz
    在 php.ini 中加上
    ; php-json package - http://pecl.php.net/package/json
    extension=json.so
     
     
    PHP | 5924 觀看 | 2013-09-03 | 標籤: javascript, php, json | Kuann Hung 上傳
  • 9d42f5ed91896f8d87d0c7fc187b10e4.pngCISSP,全稱為 Certified Information Systems Security Professional,中文譯名為信息系統安全認證專家,是由國際信息系統安全認證聯盟(International Information Systems Security Certification Consortium,(ISC)²)獨立管理的信息安全認證。2004 年 6 月,CISSP 獲得 ANSI ISO/IEC Standard 17024:2003 認定,成為信息安全方面的第一個 IT 認證。它也被美國國防部正式認定在信息保障技術和信息保障管理目錄中。CISSP 還被美國國家安全局採納作為信息系統安全工程專家程序的基準。
     
    Certified Information Systems Security Professional (CISSP) is an independent information security certification governed by International Information Systems Security Certification Consortium also known as (ISC)².
    As of January 2013, (ISC)² reports 85,285 members hold the CISSP certification world wide, in 143 countries. In June 2004, the CISSP obtained accreditation by ANSI ISO/IEC Standard 17024:2003 accreditation. It is also formally approved by the U.S. Department of Defense (DoD) in both their Information Assurance Technical (IAT) and Managerial (IAM) categories for their DoDD 8570 certification requirement. The CISSP has been adopted as a baseline for the U.S. National Security Agency's ISSEP program.
    資訊安全 | 5588 觀看 | 2013-09-02 | 標籤: cissp | Kuann Hung 上傳
  • Linux | 8375 觀看 | 2013-08-27 | 標籤: rsync | Kuann Hung 上傳
  • Linux | 6376 觀看 | 2013-08-27 | Kuann Hung 上傳
  • PHP | 4960 觀看 | 2013-08-27 | Kuann Hung 上傳