本文整理汇总了PHP中strtr函数的典型用法代码示例。如果您正苦于以下问题:PHP strtr函数的具体用法?PHP strtr怎么用?PHP strtr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了strtr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: view
/**
* Display a page with this order of priority (based on the provided page name) :
* 1. Does the page exist into local/pages/{lang}/ (this allows you to overwrite default pages)?
* 2. Does the page exist into the views available in views/pages/ folder?
* Pages are not public and we take into account the language of the connected user.
* If the page name contains the keyword export, then we don't output the default template.
* @param string $page Name of the view (and of the corresponding PHP file)
* @author Benjamin BALET <benjamin.balet@gmail.com>
*/
public function view($page = 'home')
{
$data = getUserContext($this);
$trans = array("-" => " ", "_" => " ", "." => " ");
$data['title'] = ucfirst(strtr($page, $trans));
// Capitalize the first letter
//The page containing export in their name are returning another MIMETYPE
if (strpos($page, 'export') === FALSE) {
//Don't include header and menu
$this->load->view('templates/header', $data);
$this->load->view('menu/index', $data);
}
$view = 'pages/' . $this->language_code . '/' . $page . '.php';
$pathCI = APPPATH . 'views/';
$pathLocal = FCPATH . 'local/';
//Check if we have a user-defined view
if (file_exists($pathLocal . $view)) {
$this->load->customView($pathLocal, $view, $data);
} else {
//Load the page from the default location (CI views folder)
if (!file_exists($pathCI . $view)) {
redirect('notfound');
}
$this->load->view($view, $data);
}
if (strpos($page, 'export') === FALSE) {
$this->load->view('templates/footer', $data);
}
}
示例2: __construct
/**
* Constructor
*
* @param array $data the form data as name => value
* @param string|null $suffix the optional suffix for the tmp file
* @param string|null $suffix the optional prefix for the tmp file. If null 'php_tmpfile_' is used.
* @param string|null $directory directory where the file should be created. Autodetected if not provided.
* @param string|null $encoding of the data. Default is 'UTF-8'.
*/
public function __construct($data, $suffix = null, $prefix = null, $directory = null, $encoding = 'UTF-8')
{
if ($directory === null) {
$directory = self::getTempDir();
}
$suffix = '.fdf';
$prefix = 'php_pdftk_fdf_';
$this->_fileName = tempnam($directory, $prefix);
$newName = $this->_fileName . $suffix;
rename($this->_fileName, $newName);
$this->_fileName = $newName;
$fields = '';
foreach ($data as $key => $value) {
// Create UTF-16BE string encode as ASCII hex
// See http://blog.tremily.us/posts/PDF_forms/
$utf16Value = mb_convert_encoding($value, 'UTF-16BE', $encoding);
/* Also create UTF-16BE encoded key, this allows field names containing
* german umlauts and most likely many other "special" characters.
* See issue #17 (https://github.com/mikehaertl/php-pdftk/issues/17)
*/
$utf16Key = mb_convert_encoding($key, 'UTF-16BE', $encoding);
// Escape parenthesis
$utf16Value = strtr($utf16Value, array('(' => '\\(', ')' => '\\)'));
$fields .= "<</T(" . chr(0xfe) . chr(0xff) . $utf16Key . ")/V(" . chr(0xfe) . chr(0xff) . $utf16Value . ")>>\n";
}
// Use fwrite, since file_put_contents() messes around with character encoding
$fp = fopen($this->_fileName, 'w');
fwrite($fp, self::FDF_HEADER);
fwrite($fp, $fields);
fwrite($fp, self::FDF_FOOTER);
fclose($fp);
}
示例3: entry
function entry(&$argv)
{
if (is_file($argv[0])) {
if (0 === substr_compare($argv[0], '.class.php', -10)) {
$uri = realpath($argv[0]);
if (null === ($cl = \lang\ClassLoader::getDefault()->findUri($uri))) {
throw new \Exception('Cannot load ' . $uri . ' - not in class path');
}
return $cl->loadUri($uri)->literal();
} else {
if (0 === substr_compare($argv[0], '.xar', -4)) {
$cl = \lang\ClassLoader::registerPath($argv[0]);
if (!$cl->providesResource('META-INF/manifest.ini')) {
throw new \Exception($cl->toString() . ' does not provide a manifest');
}
$manifest = parse_ini_string($cl->getResource('META-INF/manifest.ini'));
return strtr($manifest['main-class'], '.', '\\');
} else {
array_unshift($argv, 'eval');
return 'xp\\runtime\\Evaluate';
}
}
} else {
return strtr($argv[0], '.', '\\');
}
}
示例4: PMA_sanitize
/**
* Sanitizes $message, taking into account our special codes
* for formatting.
*
* If you want to include result in element attribute, you should escape it.
*
* Examples:
*
* <p><?php echo PMA_sanitize($foo); ?></p>
*
* <a title="<?php echo PMA_sanitize($foo, true); ?>">bar</a>
*
* @uses preg_replace()
* @uses strtr()
* @param string the message
* @param boolean whether to escape html in result
*
* @return string the sanitized message
*
* @access public
*/
function PMA_sanitize($message, $escape = false, $safe = false)
{
if (!$safe) {
$message = strtr($message, array('<' => '<', '>' => '>'));
}
$replace_pairs = array('[i]' => '<em>', '[/i]' => '</em>', '[em]' => '<em>', '[/em]' => '</em>', '[b]' => '<strong>', '[/b]' => '</strong>', '[strong]' => '<strong>', '[/strong]' => '</strong>', '[tt]' => '<code>', '[/tt]' => '</code>', '[code]' => '<code>', '[/code]' => '</code>', '[kbd]' => '<kbd>', '[/kbd]' => '</kbd>', '[br]' => '<br />', '[/a]' => '</a>', '[sup]' => '<sup>', '[/sup]' => '</sup>');
$message = strtr($message, $replace_pairs);
$pattern = '/\\[a@([^"@]*)@([^]"]*)\\]/';
if (preg_match_all($pattern, $message, $founds, PREG_SET_ORDER)) {
$valid_links = array('http', './Do', './ur');
foreach ($founds as $found) {
// only http... and ./Do... allowed
if (!in_array(substr($found[1], 0, 4), $valid_links)) {
return $message;
}
// a-z and _ allowed in target
if (!empty($found[2]) && preg_match('/[^a-z_]+/i', $found[2])) {
return $message;
}
}
if (substr($found[1], 0, 4) == 'http') {
$message = preg_replace($pattern, '<a href="' . PMA_linkURL($found[1]) . '" target="\\2">', $message);
} else {
$message = preg_replace($pattern, '<a href="\\1" target="\\2">', $message);
}
}
if ($escape) {
$message = htmlspecialchars($message);
}
return $message;
}
示例5: createMap
/**
* Iterate over all files in the given directory searching for classes
*
* @param \Iterator|string $path The path to search in or an iterator
* @param string $blacklist Regex that matches against the file path that exclude from the classmap.
* @param IOInterface $io IO object
* @param string $namespace Optional namespace prefix to filter by
*
* @throws \RuntimeException When the path is neither an existing file nor directory
* @return array A class map array
*/
public static function createMap($path, $blacklist = null, IOInterface $io = null, $namespace = null)
{
if (is_string($path)) {
if (is_file($path)) {
$path = array(new \SplFileInfo($path));
} elseif (is_dir($path)) {
$path = Finder::create()->files()->followLinks()->name('/\\.(php|inc|hh)$/')->in($path);
} else {
throw new \RuntimeException('Could not scan for classes inside "' . $path . '" which does not appear to be a file nor a folder');
}
}
$map = array();
foreach ($path as $file) {
$filePath = $file->getRealPath();
if (!in_array(pathinfo($filePath, PATHINFO_EXTENSION), array('php', 'inc', 'hh'))) {
continue;
}
if ($blacklist && preg_match($blacklist, strtr($filePath, '\\', '/'))) {
continue;
}
$classes = self::findClasses($filePath);
foreach ($classes as $class) {
// skip classes not within the given namespace prefix
if (null !== $namespace && 0 !== strpos($class, $namespace)) {
continue;
}
if (!isset($map[$class])) {
$map[$class] = $filePath;
} elseif ($io && $map[$class] !== $filePath && !preg_match('{/(test|fixture|example|stub)s?/}i', strtr($map[$class] . ' ' . $filePath, '\\', '/'))) {
$io->writeError('<warning>Warning: Ambiguous class resolution, "' . $class . '"' . ' was found in both "' . $map[$class] . '" and "' . $filePath . '", the first will be used.</warning>');
}
}
}
return $map;
}
示例6: evictClassMetadataFromCache
/**
* {@inheritDoc}
*/
public function evictClassMetadataFromCache(\ReflectionClass $class)
{
$path = $this->dir . '/' . strtr($class->name, '\\', '-') . '.cache.php';
if (file_exists($path)) {
unlink($path);
}
}
示例7: __construct
public function __construct($text)
{
$this->text = $text;
$text = (string) $text;
// преобразуем в строковое значение
$text = strip_tags($text);
// убираем HTML-теги
$text = str_replace(array("\n", "\r"), " ", $text);
// убираем перевод каретки
$text = preg_replace("/\\s+/", ' ', $text);
// удаляем повторяющие пробелы
$text = trim($text);
// убираем пробелы в начале и конце строки
$text = mb_strtolower($text, 'utf-8');
// переводим строку в нижний регистр
$text = strtr($text, array('а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd', 'е' => 'e', 'ё' => 'e', 'ж' => 'j', 'з' => 'z', 'и' => 'y', 'і' => 'i', 'ї' => 'і', 'й' => 'y', 'к' => 'k', 'л' => 'l', 'м' => 'm', 'н' => 'n', 'о' => 'o', 'п' => 'p', 'р' => 'r', 'с' => 's', 'т' => 't', 'у' => 'u', 'ф' => 'f', 'х' => 'h', 'ц' => 'c', 'ч' => 'ch', 'ш' => 'sh', 'щ' => 'shch', 'ы' => 'y', 'э' => 'e', 'ю' => 'yu', 'я' => 'ya', 'ъ' => '', 'ь' => ''));
// в данном случае язык
//будет укр.(изначально скрипт для русского яз.) поэтому некоторые буквы заменены или удалены, а именно ('и'=>'i')
$text = preg_replace("/[^0-9a-z-_ ]/i", "", $text);
// очищаем строку от недопустимых символов
$text = str_replace(" ", "_", $text);
// заменяем пробелы нижним подчеркиванием
$text = str_replace("-", "_", $text);
//заменяет минус на нижнее подчеркивание
$this->translit = $text;
}
示例8: decode
public static function decode($path)
{
$p = array('$system' => ZOTOP_PATH_SYSTEM, '$modules' => ZOTOP_PATH_MODULES);
$path = strtr($path, $p);
$path = path::clean($path);
return $path;
}
示例9: osc_output_string
/**
* Parse and output a user submited value
*
* @param string $string The string to parse and output
* @param array $translate An array containing the characters to parse
* @access public
*/
function osc_output_string($string, $translate = null)
{
if (empty($translate)) {
$translate = array('"' => '"');
}
return strtr(trim($string), $translate);
}
示例10: makeFriendlyUrl
public static function makeFriendlyUrl($string, $allowUnder = false, $sep = '-')
{
static $charMap = array("à" => "a", "ả" => "a", "ã" => "a", "á" => "a", "ạ" => "a", "ă" => "a", "ằ" => "a", "ẳ" => "a", "ẵ" => "a", "ắ" => "a", "ặ" => "a", "â" => "a", "ầ" => "a", "ẩ" => "a", "ẫ" => "a", "ấ" => "a", "ậ" => "a", "đ" => "d", "è" => "e", "ẻ" => "e", "ẽ" => "e", "é" => "e", "ẹ" => "e", "ê" => "e", "ề" => "e", "ể" => "e", "ễ" => "e", "ế" => "e", "ệ" => "e", "ì" => 'i', "ỉ" => 'i', "ĩ" => 'i', "í" => 'i', "ị" => 'i', "ò" => 'o', "ỏ" => 'o', "õ" => "o", "ó" => "o", "ọ" => "o", "ô" => "o", "ồ" => "o", "ổ" => "o", "ỗ" => "o", "ố" => "o", "ộ" => "o", "ơ" => "o", "ờ" => "o", "ở" => "o", "ỡ" => "o", "ớ" => "o", "ợ" => "o", "ù" => "u", "ủ" => "u", "ũ" => "u", "ú" => "u", "ụ" => "u", "ư" => "u", "ừ" => "u", "ử" => "u", "ữ" => "u", "ứ" => "u", "ự" => "u", "ỳ" => "y", "ỷ" => "y", "ỹ" => "y", "ý" => "y", "ỵ" => "y", "À" => "A", "Ả" => "A", "Ã" => "A", "Á" => "A", "Ạ" => "A", "Ă" => "A", "Ằ" => "A", "Ẳ" => "A", "Ẵ" => "A", "Ắ" => "A", "Ặ" => "A", "Â" => "A", "Ầ" => "A", "Ẩ" => "A", "Ẫ" => "A", "Ấ" => "A", "Ậ" => "A", "Đ" => "D", "È" => "E", "Ẻ" => "E", "Ẽ" => "E", "É" => "E", "Ẹ" => "E", "Ê" => "E", "Ề" => "E", "Ể" => "E", "Ễ" => "E", "Ế" => "E", "Ệ" => "E", "Ì" => "I", "Ỉ" => "I", "Ĩ" => "I", "Í" => "I", "Ị" => "I", "Ò" => "O", "Ỏ" => "O", "Õ" => "O", "Ó" => "O", "Ọ" => "O", "Ô" => "O", "Ồ" => "O", "Ổ" => "O", "Ỗ" => "O", "Ố" => "O", "Ộ" => "O", "Ơ" => "O", "Ờ" => "O", "Ở" => "O", "Ỡ" => "O", "Ớ" => "O", "Ợ" => "O", "Ù" => "U", "Ủ" => "U", "Ũ" => "U", "Ú" => "U", "Ụ" => "U", "Ư" => "U", "Ừ" => "U", "Ử" => "U", "Ữ" => "U", "Ứ" => "U", "Ự" => "U", "Ỳ" => "Y", "Ỷ" => "Y", "Ỹ" => "Y", "Ý" => "Y", "Ỵ" => "Y");
$string = strtr($string, $charMap);
$string = self::CleanUpSpecialChars($string, $allowUnder, $sep);
return strtolower($string);
}
示例11: run
public function run()
{
echo Html::beginTag('div', ['class' => 'input-group']);
if (!isset($this->options['class'])) {
$this->options['class'] = 'form-control';
}
$iconId = 'icon-' . $this->options['id'];
if (!isset($this->options['aria-describedby'])) {
$this->options['aria-describedby'] = $iconId;
}
if ($this->hasModel()) {
$replace['{input}'] = Html::activeTextInput($this->model, $this->attribute, $this->options);
} else {
$replace['{input}'] = Html::textInput($this->name, $this->value, $this->options);
}
if ($this->icon != '') {
$replace['{icon}'] = Html::tag('span', Icon::show($this->icon, [], Icon::FA), ['class' => 'input-group-addon', 'id' => $iconId]);
}
echo strtr($this->template, $replace);
echo Html::endTag('div');
$view = $this->getView();
Assets::register($view);
$idMaster = $this->hasModel() ? Html::getInputId($this->model, $this->fromField) : $this->fromField;
$idSlave = $this->options['id'];
$view->registerJs("\n \$('#{$idMaster}').syncTranslit({\n destination: '{$idSlave}',\n type: 'url',\n caseStyle: 'lower',\n urlSeparator: '-'\n });");
}
示例12: streamData
function streamData($data, $name, $time = 0, $level = -1)
{
$time = $this->dosTime($time);
$crc = crc32($data);
$dlen = strlen($data);
$level < 0 && ($level = (int) $this->level);
$level < 0 && ($level = self::LEVEL);
$data = gzdeflate($data, $level);
$zlen = strlen($data);
$name = strtr($name, '\\', '/');
$n = @iconv('UTF-8', 'CP850', $name);
// If CP850 can not represent the filename, use unicode
if ($name !== @iconv('CP850', 'UTF-8', $n)) {
$n = $name;
$h = "";
} else {
$h = "";
}
$nlen = strlen($n);
$h = "" . $h . "" . pack('V', $time) . pack('V', $crc) . pack('V', $zlen) . pack('V', $dlen) . pack('v', $nlen) . pack('v', 0);
// extra field length
echo "PK", $h, $n, $data;
$dlen = $this->dataLen;
$this->dataLen += 4 + strlen($h) + $nlen + $zlen;
$this->cdr[] = "PK" . "" . $h . pack('v', 0) . pack('v', 0) . pack('v', 0) . pack('V', 32) . pack('V', $dlen) . $n;
}
示例13: syncDictionaryItem
public static function syncDictionaryItem(\PHPMailer $mail, $keyName, $lang = '', array $params = [])
{
$app = App::getInstance();
/** @var \MD\DAO\Dictionary $dictionaryDAO */
$dictionaryDAO = $app->container->get('MD\\DAO\\Dictionary');
$config = Config::getInstance();
if (empty($lang)) {
$lang = $config->currentLocale;
}
$params['name'] = $config->partnerName;
$params['url'] = $config->getPartnerSiteUrl();
$params['affiliateUrl'] = $config->partnerUrl;
$params1 = [];
foreach ($params as $key => $value) {
$params1['{' . $key . '}'] = $value;
}
$params = $params1;
$dictionary = $dictionaryDAO->getDictionaryItem($keyName, $lang);
if (isset($dictionary)) {
$mail->isHTML(true);
$mail->Subject = strtr($dictionary->title, $params);
$mail->Body = strtr($dictionary->content, $params);
}
return $mail;
}
示例14: iteratorFilter
public function iteratorFilter($path)
{
$state = $this->getState();
$filename = ltrim(basename(' '.strtr($path, array('/' => '/ '))));
$extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
if ($state->name)
{
if (!in_array($filename, (array) $state->name)) {
return false;
}
}
if ($state->types)
{
if ((in_array($extension, ComFilesModelEntityFile::$image_extensions) && !in_array('image', (array) $state->types))
|| (!in_array($extension, ComFilesModelEntityFile::$image_extensions) && !in_array('file', (array) $state->types))
) {
return false;
}
}
if ($state->search && stripos($filename, $state->search) === false) {
return false;
}
}
示例15: append
public function append(PredictionException $exception)
{
$message = $exception->getMessage();
$message = ' ' . strtr($message, array("\n" => "\n ")) . "\n";
$this->message = rtrim($this->message . $message);
$this->exceptions[] = $exception;
}