• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP preg_replace函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中preg_replace函数的典型用法代码示例。如果您正苦于以下问题:PHP preg_replace函数的具体用法?PHP preg_replace怎么用?PHP preg_replace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了preg_replace函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: save

 /**
  * Save an uploaded file to a new location.
  *
  * @param   mixed    name of $_FILE input or array of upload data
  * @param   string   new filename
  * @param   string   new directory
  * @param   integer  chmod mask
  * @return  string   full path to new file
  */
 public static function save($file, $filename = NULL, $directory = NULL, $chmod = 0755)
 {
     // Load file data from FILES if not passed as array
     $file = is_array($file) ? $file : $_FILES[$file];
     if ($filename === NULL) {
         // Use the default filename, with a timestamp pre-pended
         $filename = time() . $file['name'];
     }
     // Remove spaces from the filename
     $filename = preg_replace('/\\s+/', '_', $filename);
     if ($directory === NULL) {
         // Use the pre-configured upload directory
         $directory = WWW_ROOT . 'files/';
     }
     // Make sure the directory ends with a slash
     $directory = rtrim($directory, '/') . '/';
     if (!is_dir($directory)) {
         // Create the upload directory
         mkdir($directory, 0777, TRUE);
     }
     //if ( ! is_writable($directory))
     //throw new exception;
     if (is_uploaded_file($file['tmp_name']) and move_uploaded_file($file['tmp_name'], $filename = $directory . $filename)) {
         if ($chmod !== FALSE) {
             // Set permissions on filename
             chmod($filename, $chmod);
         }
         //$all_file_name = array(FILE_INFO => $filename);
         // Return new file path
         return $filename;
     }
     return FALSE;
 }
开发者ID:khaled-saiful-islam,项目名称:zen_v1.0,代码行数:42,代码来源:UploadComponent.php


示例2: get_exif

 function get_exif($file)
 {
     if (!function_exists('exif_read_data')) {
         return false;
     }
     $exif = @exif_read_data($file, "IFD0");
     if ($exif === false) {
         return false;
     }
     $exif_info = exif_read_data($file, NULL, true);
     $exif_arr = $this->supported_exif();
     $new_exif = array();
     foreach ($exif_arr as $k => $v) {
         $arr = explode('.', $v);
         if (isset($exif_info[$arr[0]])) {
             if (isset($exif_info[$arr[0]][$arr[1]])) {
                 $new_exif[$k] = $exif_info[$arr[0]][$arr[1]];
             } else {
                 $new_exif[$k] = false;
             }
         } else {
             $new_exif[$k] = false;
         }
         if ($k == 'Software' && !empty($new_exif['Software'])) {
             $new_exif['Software'] = preg_replace('/([^a-zA-Z0-9_\\-,\\.\\:&#@!\\(\\)\\s]+)/i', '', $new_exif['Software']);
         }
     }
     return $new_exif;
 }
开发者ID:vluo,项目名称:myPoto,代码行数:29,代码来源:exif.class.php


示例3: parse

 /**
  * Converts a YAML string to a PHP array.
  *
  * @param string  $value                  A YAML string
  * @param Boolean $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
  * @param Boolean $objectSupport          true if object support is enabled, false otherwise
  *
  * @return array A PHP array representing the YAML string
  */
 public static function parse($value, $exceptionOnInvalidType = false, $objectSupport = false)
 {
     self::$exceptionOnInvalidType = $exceptionOnInvalidType;
     self::$objectSupport = $objectSupport;
     $value = trim($value);
     if (0 == strlen($value)) {
         return '';
     }
     if (function_exists('mb_internal_encoding') && (int) ini_get('mbstring.func_overload') & 2) {
         $mbEncoding = mb_internal_encoding();
         mb_internal_encoding('ASCII');
     }
     $i = 0;
     switch ($value[0]) {
         case '[':
             $result = self::parseSequence($value, $i);
             ++$i;
             break;
         case '{':
             $result = self::parseMapping($value, $i);
             ++$i;
             break;
         default:
             $result = self::parseScalar($value, null, array('"', "'"), $i);
     }
     // some comments are allowed at the end
     if (preg_replace('/\\s+#.*$/A', '', substr($value, $i))) {
         throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i)));
     }
     if (isset($mbEncoding)) {
         mb_internal_encoding($mbEncoding);
     }
     return $result;
 }
开发者ID:shinichi81,项目名称:Codeigniter-TDD-with-Hooks,代码行数:43,代码来源:Inline.php


示例4: get_absolute_link

/**
 * Retourne le lien absolu
 */
function get_absolute_link($relative_link, $url)
{
    /* return if already absolute URL */
    if (parse_url($relative_link, PHP_URL_SCHEME) != '') {
        return $relative_link;
    }
    /* queries and anchors */
    if ($relative_link[0] == '#' || $relative_link[0] == '?') {
        return $url . $relative_link;
    }
    /* parse base URL and convert to local variables:
       $scheme, $host, $path */
    extract(parse_url($url));
    /* remove non-directory element from path */
    $path = preg_replace('#/[^/]*$#', '', $path);
    /* destroy path if relative url points to root */
    if ($relative_link[0] == '/') {
        $path = '';
    }
    /* dirty absolute URL */
    $abs = $host . $path . '/' . $relative_link;
    /* replace '//' or '/./' or '/foo/../' with '/' */
    $re = array('#(/\\.?/)#', '#/(?!\\.\\.)[^/]+/\\.\\./#');
    for ($n = 1; $n > 0; $abs = preg_replace($re, '/', $abs, -1, $n)) {
    }
    /* absolute URL is ready! */
    return $scheme . '://' . $abs;
}
开发者ID:akoenig,项目名称:wallabag,代码行数:31,代码来源:pochePictures.php


示例5: formatPath

 private function formatPath($path)
 {
     $root = realpath(__DIR__ . '/../../../');
     $path = realpath($path);
     $relative = substr($path, strlen($root) + 1);
     return preg_replace('~/([a-z0-9-]+)(\\.[a-z0-9]+)?$~ims', '/<fg=blue>$1</fg=blue>$2', $relative);
 }
开发者ID:VasekPurchart,项目名称:khanovaskola-v3,代码行数:7,代码来源:Command.php


示例6: getVisibleStringLength

 /**
  * Compute string length of only visible characters
  *
  * @param $string
  *
  * @return int
  */
 public static function getVisibleStringLength($string)
 {
     // remove escape characters
     $pattern = '#' . static::ESCAPE_CHARACTER_REGEX . '#';
     $cleanString = preg_replace($pattern, '', $string);
     return strlen($cleanString);
 }
开发者ID:matks,项目名称:vivian,代码行数:14,代码来源:Util.php


示例7: filterWhiteSpaceOption

 protected function filterWhiteSpaceOption($input)
 {
     if (!empty($this->additionalChars)) {
         $input = str_replace(str_split($this->additionalChars), '', $input);
     }
     return preg_replace('/\\s/', '', $input);
 }
开发者ID:oz-framework,项目名称:validation,代码行数:7,代码来源:AbstractCtypeRule.php


示例8: beforeLoad

 function beforeLoad(&$params)
 {
     $basePath = JPATH_CONFIGURATION . '/administrator/components/com_jckman/editor/lang';
     $languages = JFolder::files($basePath, '.js$', 1, true);
     $js = "";
     $default = $params->get("joomlaLang", "en");
     foreach ($languages as $language) {
         $content = file_get_contents($language);
         $content = preg_replace("/\\/\\*.*?\\*\\//s", "", $content);
         $content = str_replace('"', "'", $content);
         $language = str_replace("\\", "/", $language);
         $parts = explode("/", $language);
         $lang = preg_replace("/\\.js\$/", "", array_pop($parts));
         $plugin = array_pop($parts);
         if ($lang != $default && $lang != 'en' || $plugin == 'lang') {
             //make sure we always load in default english file
             continue;
         }
         $content = preg_replace("/\\)\$/", ");", trim($content));
         if ($plugin == 'jflash') {
             $plug = 'flash';
         } else {
             $plug = $plugin;
         }
         $js .= "CKEDITOR.on('" . $plugin . "PluginLoaded', function(evt)\r\n            {\r\n               editor.lang." . $plug . " = null;\r\n               evt.data.lang = ['" . $default . "'];             \r\n               " . $content . "           \r\n            });";
     }
     //lets create JS object
     $javascript = new JCKJavascript();
     $javascript->addScriptDeclaration($js);
     return $javascript->toRaw();
 }
开发者ID:enjoy2000,项目名称:714water,代码行数:31,代码来源:languageoverrides.php


示例9: processStandardHeaders

 /**
  * Processes the standard headers that are not subdivided into other structs.
  */
 protected function processStandardHeaders()
 {
     $req = $this->request;
     $req->date = isset($_SERVER['REQUEST_TIME']) ? new DateTime("@{$_SERVER['REQUEST_TIME']}") : new DateTime();
     if (isset($_SERVER['REQUEST_METHOD'])) {
         switch ($_SERVER['REQUEST_METHOD']) {
             case 'POST':
                 $req->protocol = 'http-post';
                 break;
             case 'PUT':
                 $req->protocol = 'http-put';
                 break;
             case 'DELETE':
                 $req->protocol = 'http-delete';
                 break;
             default:
                 $req->protocol = 'http-get';
         }
     }
     $req->host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost.localdomain');
     $req->uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
     // remove the query string from the URI
     $req->uri = preg_replace('@\\?.*$@', '', $req->uri);
     // url decode the uri
     $req->uri = urldecode($req->uri);
     // remove the prefix from the URI
     $req->uri = preg_replace('@^' . preg_quote($this->properties['prefix']) . '@', '', $req->uri);
     $req->requestId = $req->host . $req->uri;
     $req->referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
     $req->variables =& $_REQUEST;
     if ($req->protocol == 'http-put') {
         $req->body = file_get_contents("php://input");
     }
 }
开发者ID:jacomyma,项目名称:GEXF-Atlas,代码行数:37,代码来源:http.php


示例10: smarty_modifier_cut

function smarty_modifier_cut($string, $length = 80, $etc = '...', $break_words = false, $middle = false)
{
    global $cfg;
    if ($length == 0) {
        return '';
    }
    $string = preg_replace('/<[^>]*?>/', '', $string);
    $string = preg_replace('/&nbsp;/', '', $string);
    $string = preg_replace('/&quot;/', '"', $string);
    $string = preg_replace('/&rdquo;/', '"', $string);
    $string = preg_replace('/&ldquo;/', '"', $string);
    $string = preg_replace('/&[a-z]*;/', ' ', $string);
    $string = preg_replace('/\\s+/', '', $string);
    if (strlen($string) > $length) {
        $length -= strlen($etc);
        if (!$break_words && !$middle) {
            $string = preg_replace('/\\s+?(\\S+)?$/', '', mb_substr($string, 0, $length + 1, $cfg['mysql_charset']));
        }
        if (!$middle) {
            return mb_substr($string, 0, $length, $cfg['mysql_charset']) . $etc;
        } else {
            return mb_substr($string, 0, $length / 2, $cfg['mysql_charset']) . $etc . mb_substr($string, -$length / 2, $cfg['mysql_charset']);
        }
        return mb_substr($string, 0, $length, $cfg['mysql_charset']) . $etc;
    } else {
        return $string;
    }
}
开发者ID:BGCX261,项目名称:zhishuicms-svn-to-git,代码行数:28,代码来源:modifier.cut.php


示例11: __construct

 /**
  */
 public function __construct($time = null)
 {
     $tz = new DateTimeZone('UTC');
     try {
         parent::__construct($time, $tz);
         return;
     } catch (Exception $e) {
     }
     /* Bug #5717 - Check for UT vs. UTC. */
     if (substr(rtrim($time), -3) === ' UT') {
         try {
             parent::__construct($time . 'C', $tz);
             return;
         } catch (Exception $e) {
         }
     }
     /* Bug #9847 - Catch paranthesized timezone information at end of date
      * string. */
     $date = preg_replace("/\\s*\\([^\\)]+\\)\\s*\$/", '', $time, -1, $i);
     if ($i) {
         try {
             parent::__construct($date, $tz);
             return;
         } catch (Exception $e) {
         }
     }
     parent::__construct('@-1', $tz);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:30,代码来源:DateTime.php


示例12: printevent

function printevent($record, $prettydate)
{
    print "\n" . strtoupper($record["title"]) . "\n";
    $again = repeatfirstinstance($record, $prettydate);
    if ($again) {
        print "See {$again[date]} for details\n";
    } else {
        print hmmpm($record["eventtime"]) . "\n";
        if ($record["locname"]) {
            print "{$record[locname]}, {$record[address]}\n";
        } else {
            print "{$record[address]}\n";
        }
        print wordwrap($record["printdescr"], 68) . "\n";
        if (!$record["hideemail"]) {
            $email = preg_replace("/@/", " at ", $record["email"]);
            $email = preg_replace("/\\./", " dot ", $email);
            if ($record["weburl"] != "") {
                print "{$email}, {$record[weburl]}\n";
            } else {
                print "{$email}\n";
            }
        } else {
            if ($record["weburl"] != "") {
                print "{$record[weburl]}\n";
            }
        }
    }
}
开发者ID:kirkendall,项目名称:shiftcal,代码行数:29,代码来源:viewbulletin.php


示例13: actionEdit

 public function actionEdit()
 {
     $calendarEntry = $this->getCalendarEntry(Yii::$app->request->get('id'));
     if ($calendarEntry == null) {
         if (!$this->contentContainer->permissionManager->can(new \humhub\modules\calendar\permissions\CreateEntry())) {
             throw new HttpException(403, 'No permission to add new entries');
         }
         $calendarEntry = new CalendarEntry();
         $calendarEntry->content->container = $this->contentContainer;
         if (Yii::$app->request->get('fullCalendar') == 1) {
             \humhub\modules\calendar\widgets\FullCalendar::populate($calendarEntry, Yii::$app->timeZone);
         }
     } elseif (!$calendarEntry->content->canEdit()) {
         throw new HttpException(403, 'No permission to edit this entry');
     }
     if ($calendarEntry->all_day) {
         // Timezone Fix: If all day event, remove time of start/end datetime fields
         $calendarEntry->start_datetime = preg_replace('/\\d{2}:\\d{2}:\\d{2}$/', '', $calendarEntry->start_datetime);
         $calendarEntry->end_datetime = preg_replace('/\\d{2}:\\d{2}:\\d{2}$/', '', $calendarEntry->end_datetime);
         $calendarEntry->start_time = '00:00';
         $calendarEntry->end_time = '23:59';
     }
     if ($calendarEntry->load(Yii::$app->request->post()) && $calendarEntry->validate() && $calendarEntry->save()) {
         // After closing modal refresh calendar or page
         $output = "<script>";
         $output .= 'if(typeof $("#calendar").fullCalendar != "undefined") { $("#calendar").fullCalendar("refetchEvents"); } else { location.reload(); }';
         $output .= "</script>";
         $output .= $this->renderModalClose();
         return $this->renderAjaxContent($output);
     }
     return $this->renderAjax('edit', ['calendarEntry' => $calendarEntry, 'contentContainer' => $this->contentContainer, 'createFromGlobalCalendar' => false]);
 }
开发者ID:podemos-info,项目名称:humhub-modules-calendar,代码行数:32,代码来源:EntryController.php


示例14: collectData

 public function collectData(array $param)
 {
     $page = 0;
     $tags = '';
     if (isset($param['p'])) {
         $page = (int) preg_replace("/[^0-9]/", '', $param['p']);
         $page = $page - 1;
         $page = $page * 50;
     }
     if (isset($param['t'])) {
         $tags = urlencode($param['t']);
     }
     $html = $this->file_get_html("http://mspabooru.com/index.php?page=post&s=list&tags={$tags}&pid={$page}") or $this->returnError('Could not request Mspabooru.', 404);
     foreach ($html->find('div[class=content] span') as $element) {
         $item = new \Item();
         $item->uri = 'http://mspabooru.com/' . $element->find('a', 0)->href;
         $item->postid = (int) preg_replace("/[^0-9]/", '', $element->getAttribute('id'));
         $item->timestamp = time();
         $item->thumbnailUri = $element->find('img', 0)->src;
         $item->tags = $element->find('img', 0)->getAttribute('alt');
         $item->title = 'Mspabooru | ' . $item->postid;
         $item->content = '<a href="' . $item->uri . '"><img src="' . $item->thumbnailUri . '" /></a><br>Tags: ' . $item->tags;
         $this->items[] = $item;
     }
 }
开发者ID:ORelio,项目名称:rss-bridge,代码行数:25,代码来源:MspabooruBridge.php


示例15: fit_screen_html_image

function fit_screen_html_image($pic_html)
{
    $pic_html = preg_replace('/<a.*>/Ui', '', $pic_html);
    $pic_html = str_replace('</a>', '', $pic_html);
    $pic_html = str_replace('<img ', '<img id="thepic" onLoad="scaleImg();" onClick="showOnclick();" ', $pic_html);
    return $pic_html;
}
开发者ID:phill104,项目名称:branches,代码行数:7,代码来源:codebase.php


示例16: fix_http_header_inject

/**
 * 修复http响应拆分漏洞(php < 5.4 ?)。暂时按照360网站安全检测的建议方案进行修正,虽然感觉strip_tags并非必须。
 * @link http://thread.gmane.org/gmane.comp.php.devel/70584
 * @link https://bugs.php.net/bug.php?id=60227
 * @author Horse Luke
 * @version 0.1 build 20131021
 */
function fix_http_header_inject($str)
{
    if (empty($str)) {
        return $str;
    }
    return trim(strip_tags(preg_replace('/( |\\t|\\r|\\n|\')/', '', $str)));
}
开发者ID:yangfannjx,项目名称:drafts,代码行数:14,代码来源:fix_http_header_inject.func.php


示例17: is_blank

 protected function is_blank($value)
 {
     if ($value === null || strlen($value) <= 0 || strlen(preg_replace('/\\s+/', '', $value)) <= 0) {
         return true;
     }
     return false;
 }
开发者ID:Garrett-Sens,项目名称:portfolio,代码行数:7,代码来源:form.php


示例18: remove_surplus

 public function remove_surplus($delimiter)
 {
     $body = preg_replace('/^.+\\n/', '', $this->body);
     if ($body) {
         $this->body = $body . "\n";
     }
 }
开发者ID:jinguanio,项目名称:whois,代码行数:7,代码来源:namebay.php


示例19: setMessage

 static function setMessage($file, $name)
 {
     jimport('joomla.filesystem.file');
     $file = str_replace('\\', '/', $file);
     if (strpos($file, '/administrator') === 0) {
         $file = str_replace('/administrator', JPATH_ADMINISTRATOR, $file);
     } else {
         $file = JPATH_SITE . '/' . $file;
     }
     $file = str_replace('//', '/', $file);
     $file_alt = preg_replace('#(com|mod)_([a-z-_]+\\.)#', '\\2', $file);
     if (!JFile::exists($file) && !JFile::exists($file_alt)) {
         $msg = JText::sprintf('NN_THIS_EXTENSION_NEEDS_THE_MAIN_EXTENSION_TO_FUNCTION', JText::_($name));
         $message_set = 0;
         $messageQueue = JFactory::getApplication()->getMessageQueue();
         foreach ($messageQueue as $queue_message) {
             if ($queue_message['type'] == 'error' && $queue_message['message'] == $msg) {
                 $message_set = 1;
                 break;
             }
         }
         if (!$message_set) {
             JFactory::getApplication()->enqueueMessage($msg, 'error');
         }
     }
 }
开发者ID:knigherrant,项目名称:decopatio,代码行数:26,代码来源:dependency.php


示例20: extract_embeds

 /**
  * Extract embedded elements from a HTML string.
  * 
  * This function returns an array of <embed> elements found in the input
  * string. Embeds without a 'src' attribute are skipped.
  * 
  * Each array item has the same basic structure as the array items
  * returned by blcUtility::extract_tags(), plus an additional 'embed_code' key 
  * that contains the HTML code for the element. If the embed element is wrapped
  * in an <object>, the 'embed_code' key contains the full HTML for the entire
  * <object> + <embed> structure.
  *  
  * @uses blcUtility::extract_tags() This function is a simple wrapper around extract_tags()
  * 
  * @param string $html
  * @return array 
  */
 function extract_embeds($html)
 {
     $results = array();
     //remove all <code></code> blocks first
     $html = preg_replace('/<code[^>]*>.+?<\\/code>/si', ' ', $html);
     //Find likely-looking <object> elements
     $objects = blcUtility::extract_tags($html, 'object', false, true);
     foreach ($objects as $candidate) {
         //Find the <embed> tag
         $embed = blcUtility::extract_tags($candidate['full_tag'], 'embed', true);
         if (empty($embed)) {
             continue;
         }
         $embed = reset($embed);
         //Take the first (and only) found <embed> element
         if (empty($embed['attributes']['src'])) {
             continue;
         }
         $embed['embed_code'] = $candidate['full_tag'];
         $results[] = $embed;
         //Remove the element so it doesn't come up when we search for plain <embed> elements.
         $html = str_replace($candidate['full_tag'], ' ', $html);
     }
     //Find <embed> elements not wrapped in an <object> element.
     $embeds = blcUtility::extract_tags($html, 'embed', false, true);
     foreach ($embeds as $embed) {
         if (!empty($embed['attributes']['src'])) {
             $embed['embed_code'] = $embed['full_tag'];
             $results[] = $embed;
         }
     }
     return $results;
 }
开发者ID:macconsultinggroup,项目名称:WordPress,代码行数:50,代码来源:embed-parser-base.php



注:本文中的preg_replace函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP preg_replace_callback函数代码示例发布时间:2022-05-15
下一篇:
PHP preg_quote函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap