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


PHP preg_split函数代码示例

本文整理汇总了PHP中preg_split函数的典型用法代码示例。如果您正苦于以下问题:PHP preg_split函数的具体用法?PHP preg_split怎么用?PHP preg_split使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: sendData

 protected static function sendData($host, $POST, $HEAD, $filepath, $mediafile, $TAIL)
 {
     $sock = fsockopen("ssl://" . $host, 443);
     fwrite($sock, $POST);
     fwrite($sock, $HEAD);
     //write file data
     $buf = 1024;
     $totalread = 0;
     $fp = fopen($filepath, "r");
     while ($totalread < $mediafile['filesize']) {
         $buff = fread($fp, $buf);
         fwrite($sock, $buff, $buf);
         $totalread += $buf;
     }
     //echo $TAIL;
     fwrite($sock, $TAIL);
     sleep(1);
     $data = fgets($sock, 8192);
     $data .= fgets($sock, 8192);
     $data .= fgets($sock, 8192);
     $data .= fgets($sock, 8192);
     $data .= fgets($sock, 8192);
     $data .= fgets($sock, 8192);
     $data .= fgets($sock, 8192);
     fclose($sock);
     list($header, $body) = preg_split("/\\R\\R/", $data, 2);
     $json = json_decode($body);
     if (!is_null($json)) {
         return $json;
     }
     return false;
 }
开发者ID:abazad,项目名称:whatsappGUI,代码行数:32,代码来源:mediauploader.php

示例2: lang_getfrombrowser

/**
 * determines the langauge settings of the browser, details see here:
 * http://aktuell.de.selfhtml.org/artikel/php/httpsprache/
 */
function lang_getfrombrowser($allowed_languages, $default_language, $lang_variable = null, $strict_mode = true)
{
    // $_SERVER['HTTP_ACCEPT_LANGUAGE'] verwenden, wenn keine Sprachvariable mitgegeben wurde
    if ($lang_variable === null && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
        $lang_variable = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
    }
    // wurde irgendwelche Information mitgeschickt?
    if (empty($lang_variable)) {
        // Nein? => Standardsprache zurückgeben
        return $default_language;
    }
    // Den Header auftrennen
    $accepted_languages = preg_split('/,\\s*/', $lang_variable);
    // Die Standardwerte einstellen
    $current_lang = $default_language;
    $current_q = 0;
    // Nun alle mitgegebenen Sprachen abarbeiten
    foreach ($accepted_languages as $accepted_language) {
        // Alle Infos über diese Sprache rausholen
        $res = preg_match('/^([a-z]{1,8}(?:-[a-z]{1,8})*)' . '(?:;\\s*q=(0(?:\\.[0-9]{1,3})?|1(?:\\.0{1,3})?))?$/i', $accepted_language, $matches);
        // war die Syntax gültig?
        if (!$res) {
            // Nein? Dann ignorieren
            continue;
        }
        // Sprachcode holen und dann sofort in die Einzelteile trennen
        $lang_code = explode('-', $matches[1]);
        // Wurde eine Qualität mitgegeben?
        if (isset($matches[2])) {
            // die Qualität benutzen
            $lang_quality = (double) $matches[2];
        } else {
            // Kompabilitätsmodus: Qualität 1 annehmen
            $lang_quality = 1.0;
        }
        // Bis der Sprachcode leer ist...
        while (count($lang_code)) {
            // mal sehen, ob der Sprachcode angeboten wird
            if (in_array(strtolower(join('-', $lang_code)), $allowed_languages)) {
                // Qualität anschauen
                if ($lang_quality > $current_q) {
                    // diese Sprache verwenden
                    $current_lang = strtolower(join('-', $lang_code));
                    $current_q = $lang_quality;
                    // Hier die innere while-Schleife verlassen
                    break;
                }
            }
            // Wenn wir im strengen Modus sind, die Sprache nicht versuchen zu minimalisieren
            if ($strict_mode) {
                // innere While-Schleife aufbrechen
                break;
            }
            // den rechtesten Teil des Sprachcodes abschneiden
            array_pop($lang_code);
        }
    }
    // die gefundene Sprache zurückgeben
    return $current_lang;
}
开发者ID:adartk,项目名称:phpsqlitecms,代码行数:64,代码来源:language_redirect.php

示例3: addUserFacebook

 /**
  * Add facebook user
  */
 public function addUserFacebook($aVals, $iFacebookUserId, $sAccessToken)
 {
     if (!defined('PHPFOX_IS_FB_USER')) {
         define('PHPFOX_IS_FB_USER', true);
     }
     //get facebook setting
     $bFbConnect = Phpfox::getParam('facebook.enable_facebook_connect');
     if ($bFbConnect == false) {
         return false;
     } else {
         if (Phpfox::getService('accountapi.facebook')->checkUserFacebook($iFacebookUserId) == false) {
             if (Phpfox::getParam('user.disable_username_on_sign_up')) {
                 $aVals['user_name'] = Phpfox::getLib('parse.input')->cleanTitle($aVals['full_name']);
             }
             $aVals['country_iso'] = null;
             if (Phpfox::getParam('user.split_full_name')) {
                 $aNameSplit = preg_split('[ ]', $aVals['full_name']);
                 $aVals['first_name'] = $aNameSplit[0];
                 unset($aNameSplit[0]);
                 $aVals['last_name'] = implode(' ', $aNameSplit);
             }
             $iUserId = Phpfox::getService('user.process')->add($aVals);
             if ($iUserId === false) {
                 return false;
             } else {
                 Phpfox::getService('facebook.process')->addUser($iUserId, $iFacebookUserId);
                 //update fb profile image to db
                 $bCheck = Phpfox::getService('accountapi.facebook')->addImagePicture($sAccessToken, $iUserId);
             }
         }
     }
     return true;
 }
开发者ID:PhpFoxPro,项目名称:Better-Mobile-Module,代码行数:36,代码来源:facebook.class.php

示例4: escapeArgument

 /**
  * Escapes a string to be used as a shell argument.
  *
  * @param string $argument The argument that will be escaped
  *
  * @return string The escaped argument
  */
 public static function escapeArgument($argument)
 {
     //Fix for PHP bug #43784 escapeshellarg removes % from given string
     //Fix for PHP bug #49446 escapeshellarg doesn't work on Windows
     //@see https://bugs.php.net/bug.php?id=43784
     //@see https://bugs.php.net/bug.php?id=49446
     if ('\\' === DIRECTORY_SEPARATOR) {
         if ('' === $argument) {
             return escapeshellarg($argument);
         }
         $escapedArgument = '';
         $quote = false;
         foreach (preg_split('/(")/', $argument, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $part) {
             if ('"' === $part) {
                 $escapedArgument .= '\\"';
             } elseif (self::isSurroundedBy($part, '%')) {
                 // Avoid environment variable expansion
                 $escapedArgument .= '^%"' . substr($part, 1, -1) . '"^%';
             } else {
                 // escape trailing backslash
                 if ('\\' === substr($part, -1)) {
                     $part .= '\\';
                 }
                 $quote = true;
                 $escapedArgument .= $part;
             }
         }
         if ($quote) {
             $escapedArgument = '"' . $escapedArgument . '"';
         }
         return $escapedArgument;
     }
     return escapeshellarg($argument);
 }
开发者ID:drickferreira,项目名称:rastreador,代码行数:41,代码来源:ProcessUtils.php

示例5: getSuggestion

 function getSuggestion($word)
 {
     if ($fh = fopen($this->tmpfile, "w")) {
         fwrite($fh, "!\n");
         fwrite($fh, "^{$word}\n");
         fclose($fh);
     } else {
         die("Error opening tmp file.");
     }
     $data = shell_exec($this->cmd);
     $returnData = array();
     $dataArr = preg_split("/\n/", $data, -1, PREG_SPLIT_NO_EMPTY);
     foreach ($dataArr as $dstr) {
         $matches = array();
         // Skip this line.
         if (strpos($dstr, "@") === 0) {
             continue;
         }
         preg_match("/\\& .* .* .*: (.*)/i", $dstr, $matches);
         if (!empty($matches[1])) {
             // For some reason, the exec version seems to add commas?
             $returnData[] = str_replace(",", "", $matches[1]);
         }
     }
     return $returnData;
 }
开发者ID:BackupTheBerlios,项目名称:morgos-svn,代码行数:26,代码来源:TinyPspellShell.class.php

示例6: formatVueGridName

 private function formatVueGridName()
 {
     $gridName = preg_split('/(?=[A-Z])/', $this->modelName);
     $gridName = implode('-', $gridName);
     $gridName = ltrim($gridName, '-');
     return $gridName = strtolower($gridName);
 }
开发者ID:evercode1,项目名称:view-maker,代码行数:7,代码来源:FormatsTokens.php

示例7: compile

 public static function compile($source, $path, $todir, $importdirs)
 {
     // call Less to compile
     $parser = new lessc();
     $parser->setImportDir(array_keys($importdirs));
     $parser->setPreserveComments(true);
     $output = $parser->compile($source);
     // update url
     $arr = preg_split(CANVASLess::$rsplitbegin . CANVASLess::$kfilepath . CANVASLess::$rsplitend, $output, -1, PREG_SPLIT_DELIM_CAPTURE);
     $output = '';
     $file = $relpath = '';
     $isfile = false;
     foreach ($arr as $s) {
         if ($isfile) {
             $isfile = false;
             $file = $s;
             $relpath = CANVASLess::relativePath($todir, dirname($file));
             $output .= "\n#" . CANVASLess::$kfilepath . "{content: \"{$file}\";}\n";
         } else {
             $output .= ($file ? CANVASPath::updateUrl($s, $relpath) : $s) . "\n\n";
             $isfile = true;
         }
     }
     return $output;
 }
开发者ID:shamsbd71,项目名称:canvas-framework,代码行数:25,代码来源:legacy.less.php

示例8: __construct

 /**
  *
  * @param String $file
  * @throws \Exception
  */
 public function __construct($file)
 {
     $this->_position = 0;
     if (is_array($file) && strlen(rtrim($file[0], chr(10) . chr(13) . "\n" . "\r")) == 400) {
         $this->file = $file;
     } else {
         if (is_file($file) && file_exists($file)) {
             $this->file = file($file);
         } else {
             if (is_string($file)) {
                 $this->file = preg_split('/\\r\\n|\\r|\\n/', $file);
                 if (empty(last($this->file))) {
                     array_pop($this->file);
                 }
             } else {
                 throw new \Exception("Arquivo: não existe");
             }
         }
     }
     $this->isRetorno = substr($this->file[0], 0, 9) == '02RETORNO' ? true : false;
     if (!in_array(substr($this->file[0], 76, 3), array_keys($this->bancos))) {
         throw new \Exception(sprintf("Banco: %s, inválido", substr($this->file[0], 76, 3)));
     }
     $this->header = new Header();
     $this->trailer = new Trailer();
 }
开发者ID:jhonleandres,项目名称:laravel-boleto,代码行数:31,代码来源:AbstractCnab.php

示例9: __construct

 /**
  * Constructs the class with given parameters and reads object related data from the bitstream.
  *
  * The following options are currently recognized:
  *  o vorbisContext -- Indicates whether to expect comments to be in the context of a vorbis bitstream or not. This
  *    option can be used to parse vorbis comments in another formats, eg FLAC, that do not use for example the
  *    framing flags. Defaults to true.
  *
  * @param HausDesign_Io_Reader $reader The reader object.
  * @param Array          $options Array of options.
  */
 public function __construct($reader, $options = array())
 {
     if (!isset($options['vorbisContext']) || $options['vorbisContext']) {
         parent::__construct($reader);
     } else {
         $this->_reader = $reader;
     }
     $this->_vendor = $this->_reader->read($this->_reader->readUInt32LE());
     $userCommentListLength = $this->_reader->readUInt32LE();
     for ($i = 0; $i < $userCommentListLength; $i++) {
         list($name, $value) = preg_split('/=/', $this->_reader->read($this->_reader->readUInt32LE()), 2);
         if (!isset($this->_comments[strtoupper($name)])) {
             $this->_comments[strtoupper($name)] = array();
         }
         $this->_comments[strtoupper($name)][] = $value;
     }
     if (!isset($options['vorbisContext']) || $options['vorbisContext']) {
         $this->_framingFlag = $this->_reader->readUInt8() & 0x1;
         if ($this->_framingFlag == 0) {
             require_once 'HausDesign/Media/Vorbis/Exception.php';
             throw new HausDesign_Media_Vorbis_Exception('Undecodable Vorbis stream');
         }
         $this->_reader->skip($this->_packetSize - $this->_reader->getOffset() + 30);
     }
 }
开发者ID:hausdesign,项目名称:zf-library,代码行数:36,代码来源:Comment.php

示例10: parse_in

 function parse_in($value)
 {
     $values = preg_split('/\\s+/', trim($value));
     switch (count($values)) {
         case 1:
             $v1 = $values[0];
             return array($v1, $v1, $v1, $v1);
         case 2:
             $v1 = $values[0];
             $v2 = $values[1];
             return array($v1, $v2, $v1, $v2);
         case 3:
             $v1 = $values[0];
             $v2 = $values[1];
             $v3 = $values[2];
             return array($v1, $v2, $v3, $v2);
         case 4:
             $v1 = $values[0];
             $v2 = $values[1];
             $v3 = $values[2];
             $v4 = $values[3];
             return array($v1, $v2, $v3, $v4);
         default:
             // We newer should get there, because 'padding' value can contain from 1 to 4 widths
             return array(0, 0, 0, 0);
     }
 }
开发者ID:isantiago,项目名称:foswiki,代码行数:27,代码来源:css.padding.inc.php

示例11: getFileForPhotoWithScale

 /**
  * getFileForPhotoWithScale function.
  * 
  * @access private
  * @param Models\Photo $photo
  * @param mixed $scale
  * @return [$file, $temp, $mtime]
  */
 private static function getFileForPhotoWithScale(Models\Photo $photo, $scale)
 {
     $extension = $photo->extension;
     $bucket = 'other';
     $path = '';
     if ($scale == 'photo') {
         if ($photo->get('modified')) {
             $path = '/' . $photo->get('id') . '_mod.' . $extension;
         } else {
             $bucket = 'photo';
             $path = rtrim('/' . ltrim($photo->get('path'), '/'), '/') . '/' . $photo->get('filename');
         }
     } elseif ($scale == 'scaled') {
         $thumbSize = Models\Preferences::valueForModuleWithKey('CameraLife', 'scaledsize');
         $path = "/{$photo->get('id')}_{$thumbSize}.{$extension}";
     } elseif ($scale == 'thumbnail') {
         $thumbSize = Models\Preferences::valueForModuleWithKey('CameraLife', 'thumbsize');
         $path = "/{$photo->get('id')}_{$thumbSize}.{$extension}";
     } elseif (is_numeric($scale)) {
         $valid = preg_split('/[, ]+/', Models\Preferences::valueForModuleWithKey('CameraLife', 'optionsizes'));
         if (!in_array($scale, $valid)) {
             throw new \Exception('This image size has not been allowed');
         }
         $path = "/{$photo->get('id')}_{$scale}.{$extension}";
     } else {
         throw new \Exception('Missing or bad size parameter');
     }
     $fileStore = Models\FileStore::fileStoreWithName($bucket);
     list($file, $temp, $mtime) = $fileStore->getFile($path);
     if (!$file) {
         $photo->generateThumbnail();
         list($file, $temp, $mtime) = $fileStore->getFile($path);
     }
     return [$file, $temp, $mtime];
 }
开发者ID:fulldecent,项目名称:cameralife,代码行数:43,代码来源:MediaController.php

示例12: init

 private function init()
 {
     $this->Controller = $this->Request->attributes->get('_template')->get('controller');
     $this->Route = $this->Request->attributes->get('_route');
     list(, $this->Vendor, $this->Bundle, ) = preg_split('/(?=[A-Z])/', $this->Request->attributes->get('_template')->get('bundle'));
     $this->BundlePath = __DIR__ . '/../../' . $this->Bundle . 'Bundle';
 }
开发者ID:hamidudc,项目名称:Proshut,代码行数:7,代码来源:FactoryController.php

示例13: api_get_canonical_id

function api_get_canonical_id($id)
{
    $alias_file = ROOT . "/.htaliases";
    $canon = api_get_request_id($id);
    if ($id == "" || !file_exists($alias_file)) {
        return $canon;
    }
    $fd = fopen($alias_file, "r");
    if ($fd == FALSE) {
        return $canon;
    }
    while (!feof($fd)) {
        $line = fgets($fd, 1024);
        if (substr($line, 0, 1) == "#") {
            continue;
        }
        $match = preg_split('/( |\\t|\\r|\\n)+/', $line);
        if ($id == $match[0]) {
            $canon = $match[1];
            break;
        }
    }
    fclose($fd);
    return $canon;
}
开发者ID:Avantians,项目名称:Textcube,代码行数:25,代码来源:api.php

示例14: parse

 /**
  * @param  string $string
  * @return Diff[]
  */
 public function parse($string)
 {
     $lines = preg_split('(\\r\\n|\\r|\\n)', $string);
     $lineCount = count($lines);
     $diffs = array();
     $diff = null;
     $collected = array();
     for ($i = 0; $i < $lineCount; ++$i) {
         if (preg_match('(^---\\s+(?P<file>\\S+))', $lines[$i], $fromMatch) && preg_match('(^\\+\\+\\+\\s+(?P<file>\\S+))', $lines[$i + 1], $toMatch)) {
             if ($diff !== null) {
                 $this->parseFileDiff($diff, $collected);
                 $diffs[] = $diff;
                 $collected = array();
             }
             $diff = new Diff($fromMatch['file'], $toMatch['file']);
             ++$i;
         } else {
             if (preg_match('/^(?:diff --git |index [\\da-f\\.]+|[+-]{3} [ab])/', $lines[$i])) {
                 continue;
             }
             $collected[] = $lines[$i];
         }
     }
     if (count($collected) && $diff !== null) {
         $this->parseFileDiff($diff, $collected);
         $diffs[] = $diff;
     }
     return $diffs;
 }
开发者ID:scrobot,项目名称:Lumen,代码行数:33,代码来源:Parser.php

示例15: import

 /**
  *
  */
 public function import($csv)
 {
     // convert to UTF-8
     $head = substr($csv, 0, 4096);
     $charset = rcube_charset::detect($head, RCUBE_CHARSET);
     $csv = rcube_charset::convert($csv, $charset);
     $head = '';
     $this->map = array();
     // Parse file
     foreach (preg_split("/[\r\n]+/", $csv) as $line) {
         $elements = $this->parse_line($line);
         if (empty($elements)) {
             continue;
         }
         // Parse header
         if (empty($this->map)) {
             $this->parse_header($elements);
             if (empty($this->map)) {
                 break;
             }
         } else {
             $this->csv_to_vcard($elements);
         }
     }
 }
开发者ID:BIGGANI,项目名称:zpanelx,代码行数:28,代码来源:rcube_csv2vcard.php


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