本文整理汇总了PHP中JString::transcode方法的典型用法代码示例。如果您正苦于以下问题:PHP JString::transcode方法的具体用法?PHP JString::transcode怎么用?PHP JString::transcode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JString
的用法示例。
在下文中一共展示了JString::transcode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testTranscode
/**
* @group String
* @covers JString::transcode
* @dataProvider transcodeData
*/
public function testTranscode($source, $from_encoding, $to_encoding, $expect)
{
$actual = JString::transcode($source, $from_encoding, $to_encoding);
$this->assertEquals($expect, $actual);
}
示例2: formatPrice
function formatPrice($price, $default = "")
{
if (!empty($price)) {
//decode charset before using number_format
$charset = 'UTF-8';
$decimal_separator = modJeaEmphasisNewestHelper::getComponentParam('decimals_separator', ',');
$thousands_separator = modJeaEmphasisNewestHelper::getComponentParam('thousands_separator', ' ');
$currency_symbol = modJeaEmphasisNewestHelper::getComponentParam('currency_symbol', '€');
$symbol_place = modJeaEmphasisNewestHelper::getComponentParam('symbol_place', 1);
jimport('joomla.utilities.string');
if (function_exists('iconv')) {
$decimal_separator = JString::transcode($decimal_separator, $charset, 'ISO-8859-1');
$thousands_separator = JString::transcode($thousands_separator, $charset, 'ISO-8859-1');
} else {
$decimal_separator = utf8_decode($decimal_separator);
$thousands_separator = utf8_decode($thousands_separator);
}
$price = number_format($price, 0, $decimal_separator, $thousands_separator);
//re-encode
if (function_exists('iconv')) {
$price = JString::transcode($price, 'ISO-8859-1', $charset);
} else {
$price = utf8_encode($price);
}
//is currency symbol before or after price?
if ($symbol_place == 1) {
return htmlentities($price . ' ' . $currency_symbol, ENT_COMPAT, $charset);
} else {
return htmlentities($currency_symbol . ' ' . $price, ENT_COMPAT, $charset);
}
} else {
return $default;
}
}
示例3: _getUrlContent
//.........这里部分代码省略.........
preg_match_all($reg, $content, $matches);
if (isset($matches[1])) {
foreach ($matches[1] as $match) {
$allimages[] = $match;
}
}
$url = JString::str_ireplace('http://', '', $url);
if (!empty($allimages)) {
for ($i = 0; $i < count($allimages); $i++) {
$img =& $allimages[$i];
if (JString::stristr($img, 'http://') === false) {
$img = 'http://' . $url . '/' . ltrim($img, '/');
}
}
}
}
// get encoding type
$reg = '/<meta http-equiv="[cC]ontent-[tT]ype" content="text\\/html;[ c]harset=*[\\"\']{0,1}([^\\"\\>]*)"/i';
preg_match($reg, $content, $matches);
$charset = '';
if (isset($matches[1])) {
$charset = $matches[1];
}
$desc = '';
$image = $image;
$info = '';
$title = '';
$reg = '/\\<meta name="description" content=*[\\"\']{0,1}([^\\"\\>]*)/i';
preg_match($reg, $content, $matches);
if (isset($matches[1])) {
$info .= '<div>' . $matches[1] . '</div>';
} else {
$info = JText::_('NO INFO AVAILABLE');
}
$reg = '/\\<title\\>(.*)\\<\\/title\\>/i';
preg_match($reg, $content, $matches);
if (isset($matches[1])) {
$title = '<div>' . $matches[1] . '</div>';
} else {
$title = JText::_('NO TITLE ON SITE');
}
$desc = '<table>';
$desc .= '<tr>';
if ($params->get('photopreview', 1)) {
$desc .= '<td valign="top" width="25%">';
$maxW = 250;
$maxH = 250;
$width = 150;
$height = 150;
$sz = @getimagesize(html_entity_decode($image));
$totalimages = count($allimages);
if (!empty($sz)) {
$width = $sz[0] > $maxW ? $width : $sz[0];
$height = $sz[1] > $maxH ? $height : $sz[1];
}
if (empty($allimages)) {
$desc .= '<span>' . JText::_('NO IMAGE') . '</span>';
} else {
$desc .= '<div id="images-wrapper">';
for ($ix = 0, $e = 1; $ix < count($allimages); $ix++, $e++) {
$display = ' style="display: none;"';
if ($ix == 0) {
$display = ' style="display: block;"';
}
$image = $allimages[$ix];
$desc .= '<img src="' . $image . '" id="photo-share-' . $e . '" width="' . $width . '" height="' . $height . '"' . $display . ' />';
}
$desc .= '<input type="hidden" id="photo-share-current" value="1" />';
$desc .= '<input type="hidden" id="photo-share-source" value="' . $allimages[0] . '" />';
$desc .= '</div>';
$desc .= '<div style="margin-top: 3px;">';
$desc .= '<a href="javascript:void(0);" onclick="prevPhoto(1);" id="prev-photo"><img src="' . JURI::root() . 'plugins/community/activitycomment/prev.png" border="0"/></a>';
$desc .= '<a href="javascript:void(0);" onclick="nextPhoto(\'' . $totalimages . '\');" id="next-photo"><img src="' . JURI::root() . 'plugins/community/activitycomment/next.png" border="0"/></a>';
$desc .= '</div>';
$desc .= '<div>';
$desc .= '<span id="image-count">1</span> ' . JText::_('OF') . ' <span id="total-count">' . $totalimages . '</span> ' . JText::_('IMAGES');
$desc .= '</div>';
}
$desc .= '</td>';
}
if ($charset) {
$title = JString::transcode($title, $charset, 'UTF-8');
$info = JString::transcode($info, $charset, 'UTF-8');
}
$desc .= '<td valign="top">';
$desc .= '<div style="font-weight:bold;">' . $title . '</div>';
$target = ' target="_blank"';
if ($params->get('shareurltarget', 1) == 0) {
$target = '';
}
$desc .= '<div style="color: #666;"><a href="http://' . $url . '"' . $target . '>http://' . $url . '</a></div>';
$desc .= '<div class="share-url-meta-info">' . $info . '</div>';
if (!$isRaw) {
$desc .= '<input type="checkbox" name="no-image" id="no-image" /><label for="no-image" style="display: inline;">' . JText::_('NO THUMBNAIL') . '</label>';
}
$desc .= '</td>';
$desc .= '</tr>';
$desc .= '</table>';
return $desc;
}
示例4: formatNumber
/**
* Format a number
*
* @param float|int $number
* @param int $decimals
* @return string
*/
function formatNumber($number = 0, $decimals = 0)
{
//verify if we need to represent decimal (ex : 2.00 = 2)
$temp = intval($number);
if ($temp - $number == 0.0) {
$decimals = 0;
}
//decode charset before using number_format
jimport('joomla.utilities.string');
if (function_exists('iconv')) {
$decimal_separator = JString::transcode($this->params->get('decimals_separator', ','), $this->_charset, 'ISO-8859-1');
$thousands_separator = JString::transcode($this->params->get('thousands_separator', ' '), $this->_charset, 'ISO-8859-1');
} else {
$decimal_separator = utf8_decode($this->params->get('decimals_separator', ','));
$thousands_separator = utf8_decode($this->params->get('thousands_separator', ' '));
}
$number = number_format($number, $decimals, $decimal_separator, $thousands_separator);
//re-encode
if (function_exists('iconv')) {
$number = JString::transcode($number, 'ISO-8859-1', $this->_charset);
} else {
$number = utf8_encode($number);
}
return $number;
}