亚洲最大看欧美片,亚洲图揄拍自拍另类图片,欧美精品v国产精品v呦,日本在线精品视频免费

  • 站長資訊網
    最全最豐富的資訊網站

    15個超實用的php正則表達式

    在這篇文章里,我已經編寫了15個超有用的正則表達式,WEB開發(fā)人員都應該將它收藏到自己的工具包。

    驗證域名
    檢驗一個字符串是否是個有效域名.

      $url = "http://komunitasweb.com/";   if (preg_match('/^(http|https|ftp)://([A-Z0-9][A-Z0-9_-]*(?:.[A-Z0-9][A-Z0-9_-]*)+):?(d+)?/?/i', $url)) {     echo "Your url is ok.";   } else {     echo "Wrong url.";   }   

    從一個字符串中 突出某個單詞
    這是一個非常有用的在一個字符串中匹配出某個單詞 并且突出它,非常有效的搜索結果

      $text = "Sample sentence from KomunitasWeb, regex has become popular in web programming. Now we learn regex. According to wikipedia, Regular expressions (abbreviated as regex or      regexp, with plural forms regexes, regexps, or regexen) are written in a formal language that can be interpreted by a regular expression processor";   $text = preg_replace("/b(regex)b/i", '<span style="background:#5fc9f6">1</span>', $text);   echo $text; 

    突出查詢結果在你的 WordPress 博客里就像剛才我說的,上面的那段代碼可以很方便的搜索出結果,而這里是一個更好的方式去執(zhí)行搜索在某個WordPress的博客上打開你的文件 search.php ,然后找到 方法 the_title() 然后用下面代碼替換掉它

      echo $title;      Now, just before the modified line, add this code:      <?php     $title   = get_the_title();     $keys= explode(" ",$s);     $title   = preg_replace('/('.implode('|', $keys) .')/iu',       '<strong>