本文整理汇总了PHP中mb_trim函数的典型用法代码示例。如果您正苦于以下问题:PHP mb_trim函数的具体用法?PHP mb_trim怎么用?PHP mb_trim使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mb_trim函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cs2cs_core2
function cs2cs_core2($lat, $lon, $to)
{
$descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
if (mb_eregi('^[a-z0-9_ ,.\\+\\-=]*$', $to) == 0) {
die("invalid arguments in command: " . $to . "\n");
}
$command = CS2CS . " +proj=latlong +ellps=WGS84 +to " . $to;
$process = proc_open($command, $descriptorspec, $pipes);
if (is_resource($process)) {
fwrite($pipes[0], $lon . " " . $lat);
fclose($pipes[0]);
$stdout = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[2]);
//
// $procstat = proc_get_status($process);
//
// neither proc_close nor proc_get_status return reasonable results with PHP5 and linux 2.6.11,
// see http://bugs.php.net/bug.php?id=32533
//
// as temporary (?) workaround, check stderr output.
// (Vinnie, 2006-02-09)
if ($stderr) {
die("proc_open() failed:<br />command='{$command}'<br />stderr='" . $stderr . "'");
}
proc_close($process);
return mb_split("\t|\n| ", mb_trim($stdout));
} else {
die("proc_open() failed, command={$command}\n");
}
}
示例2: doTransform
/**
* Validates a string as a time.
*
* @param string $value data to filter
* @return int filtered value
*/
protected function doTransform($value)
{
$value = mb_trim($value);
$regex = '/^(\\d\\d?)[\\.\\:]?(\\d\\d)?\\s*(am|pm)?$/i';
$matches = null;
if (!preg_match($regex, $value, $matches)) {
$this->triggerError();
}
$hour = $matches[1];
$min = isset($matches[2]) ? $matches[2] : false;
$am_or_pm = isset($matches[3]) ? $matches[3] : false;
if ($min === false && $am_or_pm === false) {
$this->triggerError();
}
$hour = (int) ltrim($hour, '0');
if ($hour > 23 || $am_or_pm !== false && $hour > 12) {
$this->triggerError();
}
$min = (int) ltrim($min, '0');
if ($min > 59) {
$this->triggerError();
}
if (strcasecmp($am_or_pm, 'pm') === 0) {
$hour += 12;
if ($hour == 24) {
$hour = 12;
}
} elseif (strcasecmp($am_or_pm, 'am') === 0 && $hour == 12) {
$hour = 0;
}
return $hour * 60 * 60 + $min * 60;
}
示例3: parseOutputLine
function parseOutputLine($str)
{
$nLon = 0;
$nLat = 0;
$parts = explode_multi(mb_trim($str), "\t\n ");
if (count($parts) == 3) {
if (strpos($parts[0], '\'') === false) {
preg_match('/^(\\d+)dE$/', $parts[0], $aLon);
$nLon = $aLon[1];
} else {
if (strpos($parts[0], '"') === false) {
preg_match('/^(\\d+)d(\\d+)\'E$/', $parts[0], $aLon);
$nLon = $aLon[1] + $aLon[2] / 60;
} else {
preg_match('/^(\\d+)d(\\d+)\'([\\d\\.]+)"E$/', $parts[0], $aLon);
$nLon = $aLon[1] + $aLon[2] / 60 + $aLon[3] / 3600;
}
}
if (strpos($parts[1], '\'') === false) {
preg_match('/^(\\d+)dN$/', $parts[1], $aLat);
$nLat = $aLat[1];
} else {
if (strpos($parts[1], '"') === false) {
preg_match('/^(\\d+)d(\\d+)\'N$/', $parts[1], $aLat);
$nLat = $aLat[1] + $aLat[2] / 60;
} else {
preg_match('/^(\\d+)d(\\d+)\'([\\d+\\.]+)"N$/', $parts[1], $aLat);
$nLat = $aLat[1] + $aLat[2] / 60 + $aLat[3] / 3600;
}
}
}
$coord = array('lon' => $nLon, 'lat' => $nLat);
return $coord;
}
示例4: test_encoding
function test_encoding($path)
{
static $ur_exclude = array('lang/de/ocstyle/search1/search.result.caches', 'lib2/b2evo-captcha', 'lib2/HTMLPurifier', 'lib2/html2text.class.php', 'lib2/imagebmp.inc.php', 'lib2/Net/IDNA2', 'lib2/smarty');
$contents = file_get_contents($path, false, null, 0, 2048);
$ur = stripos($contents, "Unicode Reminder");
if ($ur) {
if (mb_trim(mb_substr($contents, $ur + 17, 2)) != "メモ") {
$ur = mb_stripos($contents, "Unicode Reminder");
if (mb_trim(mb_substr($contents, $ur + 17, 2)) != "メモ") {
echo "Bad Unicode Reminder found in {$path}: " . mb_trim(mb_substr($contents, $ur + 17, 2)) . "\n";
} else {
echo "Unexpected non-ASCII chars (BOMs?) in header of {$path}\n";
}
}
} else {
$ok = false;
foreach ($ur_exclude as $exclude) {
if (mb_strpos($path, $exclude) === 0) {
$ok = true;
}
}
if (!$ok) {
echo "No Unicode Reminder found in {$path}\n";
}
}
}
示例5: test_encoding
function test_encoding($path)
{
static $ur_exclude = ['lib2/html2text.class.php', 'lib2/imagebmp.inc.php', 'lib2/Net/IDNA2'];
$contents = file_get_contents($path, false, null, 0, 2048);
$ur = stripos($contents, "Unicode Reminder");
if ($ur) {
if (mb_trim(mb_substr($contents, $ur + 17, 2)) != "メモ") {
$ur = mb_stripos($contents, "Unicode Reminder");
if (mb_trim(mb_substr($contents, $ur + 17, 2)) != "メモ") {
echo "Bad Unicode Reminder found in {$path}: " . mb_trim(mb_substr($contents, $ur + 17, 2)) . "\n";
} else {
echo "Unexpected non-ASCII chars (BOMs?) in header of {$path}\n";
}
}
} else {
$ok = false;
foreach ($ur_exclude as $exclude) {
if (mb_strpos($path, $exclude) === 0) {
$ok = true;
}
}
if (!$ok) {
echo "No Unicode Reminder found in {$path}\n";
}
}
}
示例6: index
public function index()
{
$tags = array();
if (!empty($this->data['Study']['search'])) {
$tags = mb_convert_kana(mb_trim($this->data['Study']['search']), 'as');
$tags = preg_replace('!\\s+!', ' ', $tags);
$this->passedArgs['tags'] = urlencode($tags);
}
if (!empty($this->passedArgs['tags'])) {
$tags = urldecode($this->passedArgs['tags']);
$this->data['Study']['search'] = $tags;
$tags = explode(' ', $tags);
}
$ids = null;
foreach ($tags as $key => $tag) {
if (is_null($ids)) {
$conditions = array('LOWER(Tag.tag) LIKE' => strtolower($tag));
} else {
$conditions = array('LOWER(Tag.tag) LIKE' => strtolower($tag), 'StudiesTag.study_id' => $ids);
}
$joins = array(array('table' => 'tags', 'alias' => 'Tag', 'type' => 'INNER', 'conditions' => array('StudiesTag.tag_id = Tag.id')));
$fields = array('id', 'study_id');
$ids = $this->Study->StudiesTag->find('list', compact('conditions', 'joins', 'fields'));
}
$this->paginate = array('foreignKey' => false, 'order' => array('study_date' => 'desc'), 'contain' => array('User', 'Tag'));
if (!is_null($ids)) {
$this->paginate['conditions'] = array('Study.id' => $ids);
}
$this->set('studies', $this->paginate());
}
示例7: tagData
function tagData($parser, $tagData)
{
if (mb_trim($tagData)) {
if (isset($this->stack_ref['DATA'])) {
$this->stack_ref['DATA'] .= $tagData;
} else {
$this->stack_ref['DATA'] = $tagData;
}
}
}
示例8: remove_invalid
function remove_invalid($arr)
{
$result = array();
foreach ($arr as $val) {
if (!empty($val) && mb_trim($val) !== '') {
$result[] = $val;
}
}
return $result;
}
示例9: __toString
/**
* Returns original formatted full text.
*/
function __toString()
{
$count = isset($this->parents[get_class($this)]) ? $this->parents[get_class($this)] : 0;
$prefix = str_repeat(' ', $count) . $this->type . ' ';
$str = '';
foreach ($this as $child) {
$str .= $prefix . mb_trim($child->__toString());
}
return $str;
}
示例10: beforeValidate
function beforeValidate(&$model)
{
foreach ($model->data[$model->alias] as $key => $data) {
if (is_string($data)) {
$data = preg_replace('/<link[^>]+rel="[^"]*stylesheet"[^>]*>|<script[^>]*>.*?<\\/script>|<style[^>]*>.*?<\\/style>|<!--.*?-->/i', '', $data);
$data = mb_trim($data);
$model->data[$model->alias][$key] = mb_convert_kana($data, 'a');
}
}
return true;
}
示例11: processUrl
public function processUrl($url)
{
global $opt;
$maxsize = 100 * 1024;
// max. 100kB
$content = @read_file($url, $maxsize);
if ($content === false) {
return false;
}
$xml = @simplexml_load_string($content);
if ($xml === false) {
return false;
}
if (!isset($xml->entry)) {
return false;
}
foreach ($xml->entry as $item) {
$posting = [];
$sTitle = $item->title;
if (mb_strpos($sTitle, '•') !== false) {
$sTitle = mb_trim(mb_substr($sTitle, mb_strpos($sTitle, '•') + 1));
}
$sTitle = strip_tags($sTitle);
$sTitle = htmlspecialchars_decode($sTitle);
$sTitle = preg_replace('/\\&.*\\;/U', '', $sTitle);
$nTopicId = crc32($item->id);
// workaround ...
$tUpdated = strtotime($item->updated);
$sUsername = (string) $item->author->name;
$sUsername = htmlspecialchars_decode($sUsername);
$sUsername = preg_replace('/\\&.*\\;/U', '', $sUsername);
foreach ($item->link->Attributes() as $key => $value) {
if ($key == 'href') {
$sLink = (string) $value;
}
}
$posting['id'] = $nTopicId;
$posting['title'] = $sTitle;
$posting['updated'] = $tUpdated;
$posting['username'] = $sUsername;
$posting['link'] = $sLink;
if ($nTopicId != 0) {
if (isset($this->topiclist[$nTopicId]) && $posting['updated'] > $this->topiclist[$nTopicId]['updated']) {
$this->topiclist[$nTopicId] = $posting;
} else {
if (!isset($this->topiclist[$nTopicId])) {
$this->topiclist[$nTopicId] = $posting;
}
}
}
}
return true;
}
示例12: getTitle
protected function getTitle($url)
{
if (!empty($url)) {
$HttpSocket = new HttpSocket();
$results = $HttpSocket->get($url);
$results = mb_convert_encoding($results, Configure::read('App.encoding'), 'auto');
preg_match('/<title>([^<]*)<\\/title>/i', $results, $matchs);
if (isset($matchs[1])) {
return mb_trim($matchs[1]);
}
}
return '';
}
示例13: getInline
/**
* Trims PHP tags from start/end of source for inlining.
*
* @param function $filter optional filter
* @return string code for inlining
*/
function getInline($filter = null)
{
$new = mb_trim($this->src);
// remove starting tag..
if (strncmp('<?php', $new, 5) === 0) {
$new = mb_substr($new, 5);
}
if (strncmp('<?', $new, 2) === 0 && strncmp('<?=', $new, 3) !== 0) {
$new = mb_substr($new, 2);
}
// remove ending tag
$end = mb_substr($new, mb_strlen($new) - 2);
if (strcmp($end, '?>') === 0) {
$new = mb_substr($new, 0, mb_strlen($new) - 2);
}
return _transform(mb_trim($new), $filter);
}
示例14: execute
function execute($type, &$value)
{
//配列の値はそのうち実装予定
if (is_array($value)) {
return $value;
}
switch ($type) {
case 'empty':
if (!empty($value)) {
$value = '';
}
break;
case 'alphabet':
$value = mb_convert_kana($value, 'r', $this->option_encoding);
break;
case 'numeric':
$value = mb_convert_kana($value, 'n', $this->option_encoding);
break;
case 'kanaHankaku':
$value = mb_convert_kana($value, 'k', $this->option_encoding);
break;
case 'kanaZenkaku':
$value = mb_convert_kana($value, 'KV', $this->option_encoding);
break;
case 'alphaNumeric':
$value = mb_convert_kana($value, 'a', $this->option_encoding);
break;
case 'mbTrim':
if (function_exists('mb_trim')) {
$value = mb_trim($value);
} else {
$chars = '\\s ';
$value = preg_replace("/^[{$chars}]+/u", "", $value);
$value = preg_replace("/[{$chars}]+\$/u", "", $value);
}
break;
case 'trim':
$value = trim($value);
break;
case 'point':
$value = mb_convert_kana($value, 'n', $this->option_encoding);
$value = r(a('ー', '-', '.'), a('-', '-', '.'), $value);
break;
}
return $value;
}
示例15: parse
/**
* Parses a piece of text into a number of quotations.
*
* @param T_Text_Parseable $element
*/
protected function parse(T_Text_Parseable $element)
{
$delimit = preg_quote('""');
$lf = '(?:\\r\\n|\\n|\\x0b|\\r|\\f|\\x85|^|$)';
$regex = '/' . $lf . $delimit . '\\s*' . $lf . '(.+?)' . $lf . $delimit . '([^' . $lf . ']*)' . $lf . '/su';
/* line feed at end */
// note the trailing 's', this puts the regex in multi-line mode and
// means that the 'dot' in the middle matches newlines
$content = $element->getContent();
$num = preg_match_all($regex, $content, $matches, PREG_OFFSET_CAPTURE);
if ($num < 1) {
return;
/* no change, as no quotes */
}
$offset = 0;
/* Note that the offset produced from preg_match_all is in bytes, not
unicode characters. Therefore, in the following section we do NOT use
the mb_* functions to assess length, as we are working in bytes not
characters. */
for ($i = 0; $i < $num; $i++) {
/* pre content */
if ($offset < $matches[0][$i][1]) {
$pre = substr($content, $offset, $matches[0][$i][1] - $offset);
$element->addChild(new T_Text_Plain($pre));
}
/* quote */
$quote = mb_trim($matches[1][$i][0]);
$cite = mb_trim($matches[2][$i][0]);
$element->addChild(new T_Text_Quote($cite, $quote));
/* update offset */
$offset = $matches[0][$i][1] + strlen($matches[0][$i][0]);
}
/* post content */
if ($offset < strlen($content)) {
$post = substr($content, $offset);
$element->addChild(new T_Text_Plain($post));
}
/* reset original content */
$element->setContent(null);
}