當前位置: 首頁>>代碼示例>>PHP>>正文


PHP TextCleaner::replace方法代碼示例

本文整理匯總了PHP中TextCleaner::replace方法的典型用法代碼示例。如果您正苦於以下問題:PHP TextCleaner::replace方法的具體用法?PHP TextCleaner::replace怎麽用?PHP TextCleaner::replace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在TextCleaner的用法示例。


在下文中一共展示了TextCleaner::replace方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: clean_url

 /**
  * Checks and Clean a URL
  *
  * Taked from Wordpress
  *
  * @param string $url The URL to be cleaned.
  * @param array $protocols Optional. An array of acceptable protocols.
  *        Defaults to 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet' if not set.
  * @param string $context Optional. How the URL will be used. Default is 'display'.
  * @return string The cleaned $url after the 'cleaned_url' filter is applied.
  */
 public function clean_url($url, $protocols = null, $context = 'display')
 {
     global $aprotocols;
     $original_url = $url;
     if ('' == $url) {
         return $url;
     }
     $url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$\\|*\'()\\x80-\\xff]|i', '', $url);
     $strip = array('%0d', '%0a', '%0D', '%0A');
     $url = TextCleaner::replace($strip, $url);
     $url = str_replace(';//', '://', $url);
     /* If the URL doesn't appear to contain a scheme, we
      * presume it needs http:// appended (unless a relative
      * link starting with / or a php file).
      */
     if (strpos($url, ':') === false && substr($url, 0, 1) != '/' && substr($url, 0, 1) != '#' && !preg_match('/^[a-z0-9-]+?\\.php/i', $url)) {
         $url = 'http://' . $url;
     }
     // Replace ampersands and single quotes only when displaying.
     if ('display' == $context) {
         $url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&$1', $url);
         $url = str_replace("'", ''', $url);
     }
     if (!is_array($protocols)) {
         $protocols = array('http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet');
     }
     $aprotocols = $protocols;
     if (TextCleaner::bad_protocol($url, $protocols) != $url) {
         return '';
     }
     return RMEvents::get()->run_event('rmcommon.clean_url', $url, $original_url, $context);
 }
開發者ID:txmodxoops,項目名稱:rmcommon,代碼行數:43,代碼來源:textcleaner.php


注:本文中的TextCleaner::replace方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。