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


PHP String::replace方法代码示例

本文整理汇总了PHP中String::replace方法的典型用法代码示例。如果您正苦于以下问题:PHP String::replace方法的具体用法?PHP String::replace怎么用?PHP String::replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在String的用法示例。


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

示例1: testReplace

 public function testReplace()
 {
     $string = new String("Test11");
     $this->assertEquals("Test12", $string->replace("11", "12"));
     $string = new String("Test11");
     $this->assertEquals("fest11", $string->replace("test", "fest", null, true));
 }
开发者ID:seanyainkiranina,项目名称:completecontrol,代码行数:7,代码来源:stringtest.class.php

示例2: replace

 public function replace(&$data, $oldDomain, $newDomain)
 {
     if (!empty($data)) {
         if (is_string($data)) {
             $data = parent::replace($data, $oldDomain, $newDomain);
         } elseif (is_object($data) || is_array($data)) {
             if (is_object($data)) {
                 $objectData = get_object_vars($data);
             } elseif (is_array($data)) {
                 $objectData = $data;
             }
             foreach ($objectData as $field => $value) {
                 if (is_object($data)) {
                     $data->{$field} = $this->replace($data->{$field}, $oldDomain, $newDomain);
                 } elseif (is_array($data)) {
                     $data[$field] = $this->replace($data[$field], $oldDomain, $newDomain);
                 }
             }
         } elseif (is_integer($data)) {
             //Nothing
         } elseif (is_bool($data)) {
             //Nothing
         } else {
             ob_start();
             var_dump($data);
             throw new \Exception('Unsupported operand type: ' . ob_get_clean());
         }
     }
     return $data;
 }
开发者ID:bugexorcist,项目名称:edc,代码行数:30,代码来源:Serialized.php

示例3: flush

 public static function flush($group = null, $key = null)
 {
     if ($group === null) {
         File::removeAllFrom(self::$dir);
     } else {
         if ($key == null) {
             return File::removeAllFrom(self::$dir . '/' . String::replace('.', '/', $group));
         } else {
             return File::remove(self::$dir . '/' . String::replace('.', '/', $group) . '/' . $key);
         }
     }
 }
开发者ID:wijnandmet,项目名称:Foundation,代码行数:12,代码来源:cache.php

示例4: detectUri

 /**
  * Detects uri, base path and script path of the request.
  * @return void
  */
 protected function detectUri()
 {
     $uri = $this->uri = new UriScript();
     $uri->scheme = $this->isSecured() ? 'https' : 'http';
     $uri->user = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : '';
     $uri->password = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : '';
     // host & port
     if (isset($_SERVER['HTTP_HOST'])) {
         $pair = explode(':', $_SERVER['HTTP_HOST']);
     } elseif (isset($_SERVER['SERVER_NAME'])) {
         $pair = explode(':', $_SERVER['SERVER_NAME']);
     } else {
         $pair = array('');
     }
     $uri->host = $pair[0];
     if (isset($pair[1])) {
         $uri->port = (int) $pair[1];
     } elseif (isset($_SERVER['SERVER_PORT'])) {
         $uri->port = (int) $_SERVER['SERVER_PORT'];
     }
     // path & query
     if (isset($_SERVER['REQUEST_URI'])) {
         // Apache, IIS 6.0
         $requestUri = $_SERVER['REQUEST_URI'];
     } elseif (isset($_SERVER['ORIG_PATH_INFO'])) {
         // IIS 5.0 (PHP as CGI ?)
         $requestUri = $_SERVER['ORIG_PATH_INFO'];
         if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != '') {
             $requestUri .= '?' . $_SERVER['QUERY_STRING'];
         }
     } else {
         $requestUri = '';
     }
     $tmp = explode('?', $requestUri, 2);
     $this->originalUri = new Uri($uri);
     $this->originalUri->path = $tmp[0];
     $this->originalUri->query = isset($tmp[1]) ? $tmp[1] : '';
     $this->originalUri->freeze();
     $requestUri = String::replace($requestUri, $this->uriFilter[0]);
     $tmp = explode('?', $requestUri, 2);
     $uri->path = String::replace($tmp[0], $this->uriFilter[PHP_URL_PATH]);
     $uri->path = String::fixEncoding($uri->path);
     $uri->query = isset($tmp[1]) ? $tmp[1] : '';
     // normalized uri
     $uri->canonicalize();
     // detect base URI-path - inspired by Zend Framework (c) Zend Technologies USA Inc. (http://www.zend.com), new BSD license
     $filename = isset($_SERVER['SCRIPT_FILENAME']) ? basename($_SERVER['SCRIPT_FILENAME']) : NULL;
     $scriptPath = '';
     if (isset($_SERVER['SCRIPT_NAME']) && basename($_SERVER['SCRIPT_NAME']) === $filename) {
         $scriptPath = rtrim($_SERVER['SCRIPT_NAME'], '/');
     } elseif (isset($_SERVER['PHP_SELF']) && basename($_SERVER['PHP_SELF']) === $filename) {
         $scriptPath = $_SERVER['PHP_SELF'];
     } elseif (isset($_SERVER['ORIG_SCRIPT_NAME']) && basename($_SERVER['ORIG_SCRIPT_NAME']) === $filename) {
         $scriptPath = $_SERVER['ORIG_SCRIPT_NAME'];
         // 1and1 shared hosting compatibility
     } elseif (isset($_SERVER['PHP_SELF'], $_SERVER['SCRIPT_FILENAME'])) {
         // Backtrack up the script_filename to find the portion matching php_self
         $path = $_SERVER['PHP_SELF'];
         $segs = explode('/', trim($_SERVER['SCRIPT_FILENAME'], '/'));
         $segs = array_reverse($segs);
         $index = 0;
         $last = count($segs);
         do {
             $seg = $segs[$index];
             $scriptPath = '/' . $seg . $scriptPath;
             $index++;
         } while ($last > $index && FALSE !== ($pos = strpos($path, $scriptPath)) && 0 != $pos);
     }
     // Does the scriptPath have anything in common with the request_uri?
     if (strncmp($uri->path, $scriptPath, strlen($scriptPath)) === 0) {
         // whole $scriptPath in URL
         $uri->scriptPath = $scriptPath;
     } elseif (strncmp($uri->path, $scriptPath, strrpos($scriptPath, '/') + 1) === 0) {
         // directory portion of $scriptPath in URL
         $uri->scriptPath = substr($scriptPath, 0, strrpos($scriptPath, '/') + 1);
     } elseif (strpos($uri->path, basename($scriptPath)) === FALSE) {
         // no match whatsoever; set it blank
         $uri->scriptPath = '/';
     } elseif (strlen($uri->path) >= strlen($scriptPath) && (FALSE !== ($pos = strpos($uri->path, $scriptPath)) && $pos !== 0)) {
         // If using mod_rewrite or ISAPI_Rewrite strip the script filename
         // out of scriptPath. $pos !== 0 makes sure it is not matching a value
         // from PATH_INFO or QUERY_STRING
         $uri->scriptPath = substr($uri->path, 0, $pos + strlen($scriptPath));
     } else {
         $uri->scriptPath = $scriptPath;
     }
     $uri->freeze();
 }
开发者ID:regiss,项目名称:texyla-s-Nete1-PhP-5.2,代码行数:92,代码来源:HttpRequest.php

示例5: directoryCopy

 /**
  * @param string $pathSource_
  * @param string $pathTarget_
  *
  * @throws \Components\Io_Exception
  */
 public static function directoryCopy($pathSource_, $pathTarget_)
 {
     if (false === @is_dir($pathSource_)) {
         throw new Io_Exception('io', 'Source path must be an accessible directory.');
     }
     if (false === @is_dir($pathTarget_)) {
         if (@file_exists($pathTarget_)) {
             throw new Io_Exception('io', 'Target path must not be an existing file.');
         }
         static::directoryCreate($pathTarget_);
     }
     if (false === @is_dir($pathTarget_)) {
         throw new Io_Exception('io', 'Failed to copy directory. Unable to create target directory.');
     }
     $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($pathSource_, \RecursiveDirectoryIterator::SKIP_DOTS | \RecursiveDirectoryIterator::KEY_AS_PATHNAME), \RecursiveIteratorIterator::CHILD_FIRST);
     foreach ($iterator as $entryPath => $entryInfo) {
         if ($entryInfo->isFile()) {
             $subPath = String::replace($entryPath, "{$pathSource_}/", '');
             if (false === @is_dir("{$pathTarget_}/" . dirname($subPath))) {
                 static::directoryCreate("{$pathTarget_}/" . dirname($subPath));
             }
             @copy($entryPath, "{$pathTarget_}/{$subPath}");
         }
     }
 }
开发者ID:evalcodenet,项目名称:net.evalcode.components.io,代码行数:31,代码来源:io.php

示例6: String

foreach ($a->split() as $key => $value) {
    echo "{$key}: {$value}\n";
}
// regex too!
// output:
/*
Number found: 9
Number found: 1000
*/
$b = new String('This 9 word sentence is less than 1000 letters long.');
$b->match("/([0-9]+)/")->each(function ($value) {
    echo "Number found: {$value}\n";
});
// replaces all numbers with NUMBER. Third arg must be true because last arg is a regular expression
// output: This NUMBER word sentence is less than NUMBER letters long.
echo $b->replace("/([0-9]+)/", 'NUMBER', true) . "\n";
// not using regular expressions, and lowercase
// output: this9wordsentenceislessthan1000letterslong.
echo $b->replace(' ', '')->toLower() . "\n";
// something a bit more complex
// strips the trailing 0's and 9's and splits it into an array, adds an element, reverse sorts it and turns it into an array
// output:
/*
Array
(
    [8] => hi there!
    [7] => 8
    [6] => 7
    [5] => 6
    [4] => 5
    [3] => 4
开发者ID:phdave2005,项目名称:PHP-String-Class,代码行数:31,代码来源:examples.php

示例7: buildText

 /**
  * Builds text content.
  * @return void
  */
 protected function buildText()
 {
     $text = $this->getBody();
     if ($text instanceof ITemplate) {
         $text->mail = $this;
         $this->setBody($text->__toString(TRUE));
     } elseif ($text == NULL && $this->html != NULL) {
         // intentionally ==
         $text = String::replace($this->html, array('#<(style|script|head).*</\\1>#Uis' => '', '#<t[dh][ >]#i' => " \$0", '#[ \\t\\r\\n]+#' => ' ', '#<(/?p|/?h\\d|li|br|/tr)[ >]#i' => "\n\$0"));
         $text = html_entity_decode(strip_tags($text), ENT_QUOTES, 'UTF-8');
         $this->setBody(trim($text));
     }
 }
开发者ID:regiss,项目名称:texyla-s-Nete1-PhP-5.2,代码行数:17,代码来源:Mail.php

示例8: macroAttr

 /**
  * {attr ...}
  */
 public function macroAttr($content)
 {
     return String::replace($content . ' ', '#\\)\\s+#', ')->');
 }
开发者ID:regiss,项目名称:texyla-s-Nete1-PhP-5.2,代码行数:7,代码来源:LatteMacros.php

示例9: texyElements

 /**
  * Process <texy>...</texy> elements.
  * @param  string
  * @return string
  */
 public static function texyElements($s)
 {
     return String::replace($s, '#<texy([^>]*)>(.*?)</texy>#s', callback(__CLASS__, 'texyCb'));
 }
开发者ID:regiss,项目名称:texyla-s-Nete1-PhP-5.2,代码行数:9,代码来源:TemplateFilters.php

示例10: indent

 /**
  * Indents the HTML content from the left.
  * @param  string UTF-8 encoding or 8-bit
  * @param  int
  * @param  string
  * @return string
  */
 public static function indent($s, $level = 1, $chars = "\t")
 {
     if ($level >= 1) {
         $s = String::replace($s, '#<(textarea|pre).*?</\\1#si', callback(create_function('$m', 'return strtr($m[0], " \\t\\r\\n", "\\x1F\\x1E\\x1D\\x1A");')));
         $s = String::indent($s, $level, $chars);
         $s = strtr($s, "", " \t\r\n");
     }
     return $s;
 }
开发者ID:radypala,项目名称:maga-website,代码行数:16,代码来源:TemplateHelpers.php

示例11: getRelativePath

 public function getRelativePath(Io_Path $path_)
 {
     if ($this->isFile()) {
         $directory = $this->getParent();
     } else {
         $directory = $this;
     }
     if ($directory->isParentOf($path_)) {
         return Io::path(ltrim(String::replace($path_->m_path, str_pad($directory->m_path, 1, '/', STR_PAD_RIGHT), ''), '/'));
     }
     $level = 1;
     $segments = explode('/', $directory->m_path);
     $path = $path_->m_path;
     while (array_pop($segments)) {
         if (!($current = implode('/', $segments))) {
             $current = '/';
         }
         if (0 === mb_strpos($path, $current)) {
             if ('/' === $current) {
                 $subPath = $path;
             } else {
                 $subPath = String::replace($path, $current, '');
             }
             return str_repeat('../', $level) . ltrim($subPath, '/');
         }
         $level++;
     }
     return $file_->getPath();
 }
开发者ID:evalcodenet,项目名称:net.evalcode.components.io,代码行数:29,代码来源:path.php

示例12: detectUri

 protected function detectUri()
 {
     $uri = $this->uri = new UriScript();
     $uri->scheme = $this->isSecured() ? 'https' : 'http';
     $uri->user = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : '';
     $uri->password = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : '';
     if (isset($_SERVER['HTTP_HOST'])) {
         $pair = explode(':', $_SERVER['HTTP_HOST']);
     } elseif (isset($_SERVER['SERVER_NAME'])) {
         $pair = explode(':', $_SERVER['SERVER_NAME']);
     } else {
         $pair = array('');
     }
     $uri->host = $pair[0];
     if (isset($pair[1])) {
         $uri->port = (int) $pair[1];
     } elseif (isset($_SERVER['SERVER_PORT'])) {
         $uri->port = (int) $_SERVER['SERVER_PORT'];
     }
     if (isset($_SERVER['REQUEST_URI'])) {
         $requestUri = $_SERVER['REQUEST_URI'];
     } elseif (isset($_SERVER['ORIG_PATH_INFO'])) {
         $requestUri = $_SERVER['ORIG_PATH_INFO'];
         if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != '') {
             $requestUri .= '?' . $_SERVER['QUERY_STRING'];
         }
     } else {
         $requestUri = '';
     }
     $tmp = explode('?', $requestUri, 2);
     $this->originalUri = new Uri($uri);
     $this->originalUri->path = $tmp[0];
     $this->originalUri->query = isset($tmp[1]) ? $tmp[1] : '';
     $this->originalUri->freeze();
     $requestUri = String::replace($requestUri, $this->uriFilter[0]);
     $tmp = explode('?', $requestUri, 2);
     $uri->path = String::replace($tmp[0], $this->uriFilter[PHP_URL_PATH]);
     $uri->path = String::fixEncoding($uri->path);
     $uri->query = isset($tmp[1]) ? $tmp[1] : '';
     $uri->canonicalize();
     $filename = isset($_SERVER['SCRIPT_FILENAME']) ? basename($_SERVER['SCRIPT_FILENAME']) : NULL;
     $scriptPath = '';
     if (isset($_SERVER['SCRIPT_NAME']) && basename($_SERVER['SCRIPT_NAME']) === $filename) {
         $scriptPath = rtrim($_SERVER['SCRIPT_NAME'], '/');
     } elseif (isset($_SERVER['PHP_SELF']) && basename($_SERVER['PHP_SELF']) === $filename) {
         $scriptPath = $_SERVER['PHP_SELF'];
     } elseif (isset($_SERVER['ORIG_SCRIPT_NAME']) && basename($_SERVER['ORIG_SCRIPT_NAME']) === $filename) {
         $scriptPath = $_SERVER['ORIG_SCRIPT_NAME'];
     } elseif (isset($_SERVER['PHP_SELF'], $_SERVER['SCRIPT_FILENAME'])) {
         $path = $_SERVER['PHP_SELF'];
         $segs = explode('/', trim($_SERVER['SCRIPT_FILENAME'], '/'));
         $segs = array_reverse($segs);
         $index = 0;
         $last = count($segs);
         do {
             $seg = $segs[$index];
             $scriptPath = '/' . $seg . $scriptPath;
             $index++;
         } while ($last > $index && FALSE !== ($pos = strpos($path, $scriptPath)) && 0 != $pos);
     }
     if (strncmp($uri->path, $scriptPath, strlen($scriptPath)) === 0) {
         $uri->scriptPath = $scriptPath;
     } elseif (strncmp($uri->path, $scriptPath, strrpos($scriptPath, '/') + 1) === 0) {
         $uri->scriptPath = substr($scriptPath, 0, strrpos($scriptPath, '/') + 1);
     } elseif (strpos($uri->path, basename($scriptPath)) === FALSE) {
         $uri->scriptPath = '/';
     } elseif (strlen($uri->path) >= strlen($scriptPath) && (FALSE !== ($pos = strpos($uri->path, $scriptPath)) && $pos !== 0)) {
         $uri->scriptPath = substr($uri->path, 0, $pos + strlen($scriptPath));
     } else {
         $uri->scriptPath = $scriptPath;
     }
     $uri->freeze();
 }
开发者ID:jiriknesl,项目名称:mvc-exception-demo,代码行数:73,代码来源:loader.php

示例13: replace

 public function replace()
 {
     $str = new String('www.m�ller.com');
     $this->assertEquals(new String('m�ller'), $str->replace('www.')->replace('.com'));
     $this->assertEquals(new String('muller'), $str->replace('�', 'u'));
 }
开发者ID:Gamepay,项目名称:xp-framework,代码行数:6,代码来源:StringTest.class.php

示例14: formatArray

    /**
     * Formats parameters to PHP array.
     * @param  string
     * @param  string
     * @return string
     */
    public static function formatArray($s, $prefix = '')
    {
        $s = String::replace(trim($s), '~
				' . self::RE_STRING . '|                          ## single or double quoted string
				(?<=[,=(]|=>|^)\\s*([a-z\\d_]+)(?=\\s*[,=)]|$)   ## 1) symbol
			~xi', callback(__CLASS__, 'cbArgs'));
        $s = String::replace($s, '#\\$(' . self::RE_IDENTIFIER . ')\\s*=>#', '"$1" =>');
        return $s === '' ? '' : $prefix . "array({$s})";
    }
开发者ID:regiss,项目名称:texyla-s-Nete1-PhP-5.2,代码行数:15,代码来源:LatteFilter.php

示例15: testReplace

 public function testReplace()
 {
     $string = new String("hoge huga");
     $this->assertTrue($string->replace("hoge", "foo")->equals("foo huga"));
 }
开发者ID:reoring,项目名称:sabel,代码行数:5,代码来源:String.php


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