当前位置: 首页>>代码示例>>PHP>>正文


PHP preg_replace函数代码示例

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


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


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