本文整理汇总了PHP中mb_str_replace函数的典型用法代码示例。如果您正苦于以下问题:PHP mb_str_replace函数的具体用法?PHP mb_str_replace怎么用?PHP mb_str_replace使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mb_str_replace函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
public function render()
{
$uri = $_SERVER['REQUEST_URI'];
$temp = mb_str_replace("-", " ", substr($uri, strrpos($uri, "/") + 1));
switch (mb_strtolower($temp)) {
case "wildernessone":
$ViewData['search'] = "WildernessOne";
break;
case "geotrak":
$ViewData['search'] = "GeoTrak";
break;
case "oceanx":
$ViewData['search'] = "OceanX";
break;
}
$ViewData['title'] = "Shop | Peak Outdoor Adventure";
$ViewData['copyright'] = date("Y");
$ViewData['stylesheets'] = ["index", "shop"];
$ViewData['javascript'] = ["jquery", "shop"];
$products = json_decode(file_get_contents(__DIR__ . "\\..\\..\\Data\\products.json"));
foreach ($products as $product) {
if (mb_strtolower($product->collection) === mb_strtolower($ViewData['search'])) {
$ViewData['products'][] = $product;
}
}
foreach ($products as $product) {
$ViewData['categories'][] = $product->category;
}
$ViewData['categories'] = array_unique($ViewData['categories']);
foreach ($products as $product) {
$ViewData['collections'][] = $product->collection;
}
$ViewData['collections'] = array_unique($ViewData['collections']);
echo $this->razr->render('Templates\\Shop\\index.razr.php', $ViewData);
}
示例2: smarty_modifier_replace
/**
* Smarty replace modifier plugin
*
* Type: modifier<br>
* Name: replace<br>
* Purpose: simple search/replace
*
* @link http://smarty.php.net/manual/en/language.modifier.replace.php replace (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @author Uwe Tews
* @param string $
* @param string $
* @param string $
* @return string
*/
function smarty_modifier_replace($string, $search, $replace)
{
if (!function_exists('mb_str_replace')) {
// simulate the missing PHP mb_str_replace function
function mb_str_replace($needles, $replacements, $haystack)
{
$rep = (array) $replacements;
foreach ((array) $needles as $key => $needle) {
$replacement = $rep[$key];
$needle_len = mb_strlen($needle);
$replacement_len = mb_strlen($replacement);
$pos = mb_strpos($haystack, $needle, 0);
while ($pos !== false) {
$haystack = mb_substr($haystack, 0, $pos) . $replacement . mb_substr($haystack, $pos + $needle_len);
$pos = mb_strpos($haystack, $needle, $pos + $replacement_len);
}
}
return $haystack;
}
}
if (function_exists('mb_substr')) {
return mb_str_replace($search, $replace, $string);
} else {
return str_replace($search, $replace, $string);
}
}
示例3: mb_str_replace
/**
* マルチバイト対応 str_replace()
*
* @param mixed $search 検索文字列(またはその配列)
* @param mixed $replace 置換文字列(またはその配列)
* @param mixed $subject 対象文字列(またはその配列)
* @param string $encoding 文字列のエンコーディング(省略: 内部エンコーディング)
* @return mixed subject 内の search を replace で置き換えた文字列
*
* この関数の $search, $replace, $subject は配列に対応していますが、
* $search, $replace が配列の場合の挙動が PHP 標準の str_replace() と異なります。
*/
function mb_str_replace($search, $replace, $subject, $encoding = 'auto')
{
if (!is_array($search)) {
$search = array($search);
}
if (!is_array($replace)) {
// PHP manual:
// search が配列で replace が文字列の場合、
// この置換文字列が search の各値について使用されます。
//
// array_fill_keysは5.2以上なので使えない...
$replace = array_combine(array_keys($search), array_fill(0, count($search), $replace));
}
if (strtolower($encoding) === 'auto') {
$encoding = mb_internal_encoding();
}
// $subject が複数ならば各要素に繰り返し適用する
if (is_array($subject) || $subject instanceof Traversable) {
$result = array();
foreach ($subject as $key => $val) {
$result[$key] = mb_str_replace($search, $replace, $val, $encoding);
}
return $result;
}
$currentpos = 0;
// 現在の検索開始位置
while (true) {
// $currentpos 以降で $search のいずれかが現れる位置を検索する
$index = -1;
// 見つけた文字列(最も前にあるもの)の $search の index
$minpos = -1;
// 見つけた文字列(最も前にあるもの)の位置
foreach ($search as $key => $find) {
if ($find == '') {
continue;
}
$findpos = mb_strpos($subject, $find, $currentpos, $encoding);
if ($findpos !== false) {
if ($minpos < 0 || $findpos < $minpos) {
$minpos = $findpos;
$index = $key;
}
}
}
// $search のいずれも見つからなければ終了
if ($minpos < 0) {
break;
}
// 置換実行
$replaced = array_key_exists($index, $replace) ? $replace[$index] : '';
$subject = mb_substr($subject, 0, $minpos, $encoding) . $replaced . mb_substr($subject, $minpos + mb_strlen($search[$index], $encoding), mb_strlen($subject, $encoding), $encoding);
// 「現在位置」を $r の直後に設定
$currentpos = $minpos + mb_strlen($replaced, $encoding);
}
return $subject;
}
示例4: formatRow
protected function formatRow(array $row)
{
$ret = array_map(function ($cell) {
$cell = mb_convert_encoding((string) $cell, $this->outputCharset, $this->inputCharset);
if (!preg_match('/[",\\x0d\\x0a]/', $cell)) {
return $cell;
}
return '"' . mb_str_replace('"', '""', $cell, $this->outputCharset) . '"';
}, $row);
return implode(',', $ret);
}
示例5: replace
public static function replace($haystack, $needle, $replace, $regex = false)
{
if ($regex) {
$r = preg_replace($needle, $replace, $haystack);
} else {
if (String::$multibyte) {
$r = mb_str_replace($needle, $replace, $haystack);
} else {
$r = str_replace($needle, $replace, $haystack);
}
}
return new String($r);
}
示例6: AddExtraHTMLToSidebar
public function AddExtraHTMLToSidebar(&$company)
{
define('API', 'PS');
require_once 'siteadmin/includes/config/affiliatewindow.php';
$result = CPHelper::getStaggImageHTML($company['staggurl']);
$result .= '<div id="sidebar-merchantDescription-main"><h3>' . (empty($company['sidebar_title']) ? 'Quick Glance' : $company['sidebar_title']) . '</h3>';
$result .= mb_str_replace('{logo}', '<img src="' . $company['logourl'] . '" style="float:left; margin:5px;"/>', $company['sidebar']);
if (!empty($company['displayurl'])) {
list($cloakedURL, $realURL) = CPHelper::getCompanyURLs($company['id'], $company['displayurl'], $company['source']);
$result .= '<ul><li class="official-website"><h4>Official Website</h4><a href="' . $cloakedURL . '" target="_blank">' . $realURL . '</a></li></ul>';
}
$result .= '</div>';
$company['sidebar'] = $result;
}
示例7: arabicToPersian
function arabicToPersian($inp)
{
$out = str_replace("ي", "ی", $inp);
$out = str_replace("ك", "ک", $out);
$out = $out == 'امام خمینی' ? 'تهران' : $out;
$out = mb_str_replace(array("ـ", " "), "", $out);
if ($out == 'خرمآباد' || $out == 'خرماباد') {
$out = 'خرمآباد';
}
switch ($out) {
case 'Tehran':
$out = 'تهران';
break;
}
return $out;
}
示例8: validURLCheck
/**
* Prueft die URL damit keine boesen URLS uebergeben werden koennen
* @param $param
*/
function validURLCheck($param)
{
if (strstr($param, '://')) {
// Der APP_ROOT muss in der URL vorkommen, sonfern es kein relativer Pfad ist
// HTTPS und HTTP
if (mb_strpos($param, APP_ROOT) !== 0 && mb_strpos(mb_str_replace("http://", "https://", $param), APP_ROOT) !== 0 && mb_strpos(mb_str_replace("https://", "http://", $param), APP_ROOT) !== 0) {
$text = "Dies ist eine automatische Mail.\nEs wurde eine mögliche XSS Attacke durchgefuehrt:\n";
$text .= "\nFolgende URL wurde versucht aufzurufen: \n" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$text .= "\n\nIP des Aufrufers: " . $_SERVER['REMOTE_ADDR'];
$text .= "\n\nUserAgent: " . $_SERVER['HTTP_USER_AGENT'];
$text .= "\n\nAuffälliger Value: {$param}";
$mail = new mail(MAIL_ADMIN, 'no-reply@' . DOMAIN, 'Versuchte XSS Attacke', $text);
$mail->send();
die('Invalid URL detected');
}
}
}
示例9: render
public function render()
{
$uri = $_SERVER['REQUEST_URI'];
$id = mb_str_replace("-", " ", substr($uri, strrpos($uri, "/") + 1));
$ViewData['title'] = "Product Details | Peak Outdoor Adventure";
$ViewData['copyright'] = date("Y");
$ViewData['stylesheets'] = ["details"];
$ViewData['javascript'] = ["jquery", "details"];
$products = json_decode(file_get_contents(__DIR__ . "\\..\\..\\Data\\products.json"));
foreach ($products as $product) {
if ($product->id === intval($id, 10)) {
$ViewData['product'] = $product;
break;
}
}
echo $this->razr->render('Templates\\Shop\\details.razr.php', $ViewData);
}
示例10: testMbStrReplace
/**
* Text mb_replace() functionality
*
* @dataProvider getReplaceStringProvider
* @var mixed $search
* @var mixed $replace
* @var string $subject
* @var string $expectedResult
* @var int $expectedCount
* @return void
*/
public function testMbStrReplace($search, $replace, $subject, $expectedResult, $expectedCount)
{
//echo $url . "\n";
try {
self::startTimer('mb_str_replace', microtime(true));
$result = mb_str_replace($search, $replace, $subject, $count);
self::endTimer('mb_str_replace', microtime(true));
$this->assertSame($expectedResult, $result, "Mismatch in result");
$this->assertSame($expectedCount, $count, "Mismatch in count");
} catch (Exception $e) {
echo "Exception " . $e->getMessage() . " on subject: '{$subject}'\n";
var_dump($search);
var_dump($replace);
// rethrow it
throw $e;
}
}
示例11: mb_str_replace
private function mb_str_replace($search, $replace, $subject, &$count = 0)
{
if (!is_array($subject)) {
$searches = is_array($search) ? array_values($search) : array($search);
$replacements = is_array($replace) ? array_values($replace) : array($replace);
$replacements = array_pad($replacements, count($searches), '');
foreach ($searches as $key => $search) {
$parts = mb_split(preg_quote($search), $subject);
$count += count($parts) - 1;
$subject = implode($replacements[$key], $parts);
}
} else {
foreach ($subject as $key => $value) {
$subject[$key] = mb_str_replace($search, $replace, $value, $count);
}
}
return $subject;
}
示例12: smarty_block_replace
/**
* Replaces a smarty block with an other one.
* If the PHP multibyte (mb) extension is installed this
* function is multibyte char aware
*
* The first parameter has one 'search' and one 'replace' key
*
* @param array $params
* @param string $content
* @param mixed $smarty
* @param int $repeat
* @param string $template
* @return string
*/
function smarty_block_replace($params, $content, $smarty, &$repeat, $template)
{
if (is_null($content)) {
return;
}
if (empty($params['search'])) {
return $content;
}
if (empty($params['replace'])) {
$params['replace'] = '';
}
if (function_exists('mb_substr')) {
require_once SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php';
return mb_str_replace($params['search'], $params['replace'], $content);
} else {
return str_replace($params['search'], $params['replace'], $content);
}
}
示例13: normalize_uri
private function normalize_uri($uri)
{
// Remove query string if any
if (FALSE !== strpos($uri, "?")) {
echo $uri = substr($uri, 0, strpos($uri, "?"));
}
// Trim leading and trailing slashes
$uri = trim($uri, "/");
// Escape slashes for RegEx
$uri = mb_str_replace("/", "\\/", $uri);
// Escape actual dots
$uri = mb_str_replace(".", "\\.", $uri);
// Swap (:num) expression
$uri = mb_str_replace("(:num)", "[0-9]+", $uri);
// Swap (:alpha) expression
$uri = mb_str_replace("(:alpha)", "[A-Za-z]+", $uri);
$uri = "/^" . $uri . "\$/";
return $uri;
}
示例14: mb_str_replace
function mb_str_replace($search, $replace, $subject, $encoding = 'auto')
{
if (!is_array($search)) {
$search = array($search);
}
if (!is_array($replace)) {
$replace = array($replace);
}
if (strtolower($encoding) === 'auto') {
$encoding = mb_internal_encoding();
}
if (is_array($subject)) {
$result = array();
foreach ($subject as $key => $val) {
$result[$key] = mb_str_replace($search, $replace, $val, $encoding);
}
return $result;
}
$currentpos = 0;
while (true) {
$index = $minpos = -1;
foreach ($search as $key => $find) {
if ($find == '') {
continue;
}
$findpos = mb_strpos($subject, $find, $currentpos, $encoding);
if ($findpos !== false) {
if ($minpos < 0 || $findpos < $minpos) {
$minpos = $findpos;
$index = $key;
}
}
}
if ($minpos < 0) {
break;
}
$r = array_key_exists($index, $replace) ? $replace[$index] : '';
$subject = sprintf('%s%s%s', mb_substr($subject, 0, $minpos, $encoding), $r, mb_substr($subject, $minpos + mb_strlen($search[$index], $encoding), mb_strlen($subject, $encoding), $encoding));
$currentpos = $minpos + mb_strlen($r, $encoding);
}
return $subject;
}
示例15: mb_str_replace
function mb_str_replace($search, $replace, $subject, &$count = 0)
{
if (!is_array($subject)) {
// Normalize $search and $replace so they are both arrays of the same length
$searches = is_array($search) ? array_values($search) : array($search);
$replacements = is_array($replace) ? array_values($replace) : array($replace);
$replacements = array_pad($replacements, count($searches), '');
foreach ($searches as $key => $search) {
$parts = mb_split(preg_quote($search), $subject);
$count += count($parts) - 1;
$subject = implode($replacements[$key], $parts);
}
} else {
// Call mb_str_replace for each subject in array, recursively
foreach ($subject as $key => $value) {
$subject[$key] = mb_str_replace($search, $replace, $value, $count);
}
}
return $subject;
}