• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP string函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: it_is_chainable

 /**
  * @test
  */
 public function it_is_chainable()
 {
     $this->assertInstanceOf(\Spatie\String\Str::class, string('foo/bar/baz')->segment('/', 0));
     $this->assertInstanceOf(\Spatie\String\Str::class, string('foo/bar/baz')->firstSegment('/'));
     $this->assertInstanceOf(\Spatie\String\Str::class, string('foo/bar/baz')->lastSegment('/'));
     $this->assertInstanceOf(\Spatie\String\Str::class, string('foo/bar/baz')->pop('/'));
 }
开发者ID:sidis405,项目名称:area.dev,代码行数:10,代码来源:SegmentTest.php


示例2: mysql_to_json

function mysql_to_json($connection_name, $table_name, $file_name)
{
    // Verifies that table name and connection to MySQL exist.
    if (!$connection_name || !$table_name) {
        return false;
    }
    // If the user did not enter a desired file name, a unique one will be initiated.
    if (!$file_name) {
        $file_name = "new_json_file" . idate("U");
    }
    // Type casts input variables to strings in the case that the user entered a different variable type.
    $table_name = string($table_name);
    $file_name = string($file_name);
    // Query data from MySQL server.
    $data_query = "SELECT * FROM {$table_name}";
    $data_request = @mysqli_query($connection_name, $data_query);
    // Insert queried data into an array.
    $data_saved[] = array();
    while ($entry = mysqli_fetch_assoc($data_request)) {
        $data_saved[] = $entry;
    }
    // Copy array data to file.
    $file_wrtie = fopen($file_name, 'w');
    fwrite($file_write, json_encode($data_saved));
    fclose($file_write);
    // Return true to let the user know that everything ran successfully.
    return true;
}
开发者ID:jimmygrzybek,项目名称:MySQL-Table-to-JSON,代码行数:28,代码来源:json_mysql_converter.php


示例3: seedAdmins

 protected function seedAdmins()
 {
     $users = ['Willem' => 'Van Bockstal', 'Freek' => 'Van der Herten', 'Rogier' => 'De Boevé', 'Sebastian' => 'De Deyne'];
     foreach ($users as $firstName => $lastName) {
         factory(User::class)->create(['email' => strtolower($firstName) . '@spatie.be', 'password' => app()->env == 'local' ? strtolower($firstName) : string()->random(), 'first_name' => $firstName, 'last_name' => $lastName, 'role' => UserRole::ADMIN, 'status' => UserStatus::ACTIVE]);
     }
 }
开发者ID:bjrnblm,项目名称:blender,代码行数:7,代码来源:UserSeeder.php


示例4: seedAdmins

 public function seedAdmins()
 {
     $users = ['Willem' => 'Van Bockstal', 'Freek' => 'Van der Herten', 'Rogier' => 'De Boevé', 'Sebastian' => 'De Deyne'];
     collect($users)->each(function ($lastName, $firstName) {
         $password = app()->environment('local') ? strtolower($firstName) : string()->random();
         User::create(['email' => strtolower($firstName) . '@spatie.be', 'password' => bcrypt($password), 'first_name' => $firstName, 'last_name' => $lastName, 'role' => UserRole::ADMIN(), 'status' => UserStatus::ACTIVE()]);
     });
 }
开发者ID:spatie-custom,项目名称:blender,代码行数:8,代码来源:BackUserSeeder.php


示例5: fragment

/**
 * Get a translated fragment's text. Since this utility function is occasionally used in route files, there's also a
 * check for the database connection to return a fallback fragment in local environments.
 *
 * @param string $locale
 *
 * @return \Spatie\String\Str | string
 */
function fragment(string $name, $locale = null)
{
    $locale = $locale ?: content_locale();
    $fragment = App\Models\Fragment::findByName($name);
    if (!$fragment) {
        return $name;
    }
    return string($fragment->getTranslation($locale)->text);
}
开发者ID:vanslambrouckd,项目名称:blender,代码行数:17,代码来源:helpers.php


示例6: performConversion

 /**
  * Perform the conversion.
  *
  * @param \Spatie\MediaLibrary\Media $media
  * @param Conversion $conversion
  * @param string $copiedOriginalFile
  *
  * @return string
  */
 public function performConversion(Media $media, Conversion $conversion, string $copiedOriginalFile)
 {
     $conversionTempFile = pathinfo($copiedOriginalFile, PATHINFO_DIRNAME) . '/' . string()->random(16) . $conversion->getName() . '.' . $media->extension;
     File::copy($copiedOriginalFile, $conversionTempFile);
     foreach ($conversion->getManipulations() as $manipulation) {
         GlideImage::create($conversionTempFile)->modify($manipulation)->save($conversionTempFile);
     }
     return $conversionTempFile;
 }
开发者ID:spatie,项目名称:laravel-medialibrary,代码行数:18,代码来源:FileManipulator.php


示例7: my_plugin_menu

function my_plugin_menu()
{
    $user = string(wp_get_current_user());
    echo $user;
    if (in_array("author", (array) $user->roles)) {
        echo '';
    }
    add_dashboard_page('Tutors', 'Tutors', 'read', 'myuniqueidentifier', 'my_plugin_options');
    add_dashboard_page('View Students', 'Students', 'read', 'myuniqueidentifier1', 'ctc_students');
}
开发者ID:LucasBullen,项目名称:engLinks,代码行数:10,代码来源:menuBuilding.php


示例8: getBody

 /**
  * Get body and/or body segments
  * 
  * @param  bool|string $spec 
  * @return string|array|null
  */
 public function getBody($spec = false)
 {
     if (false === $spec) {
         return $this->outputBody();
     } elseif (true === $spec) {
         return $this->_body;
     } elseif (is - string($spec) && isset($this->_body[$spec])) {
         return $this->_body[$spec];
     }
     return null;
 }
开发者ID:RobertGresdal,项目名称:widget-testcase-framework,代码行数:17,代码来源:HttpTestCase.php


示例9: compile

 private function compile(array $tokens)
 {
     $cg = (object) ['ts' => TokenStream::fromSlice($tokens), 'parsers' => []];
     traverse(rtoken('/^(T_\\w+)·(\\w+)$/')->onCommit(function (Ast $result) use($cg) {
         $token = $result->token();
         $id = $this->lookupCapture($token);
         $type = $this->lookupTokenType($token);
         $cg->parsers[] = token($type)->as($id);
     }), ($parser = chain(rtoken('/^·\\w+$/')->as('type'), token('('), optional(ls(either(future($parser)->as('parser'), chain(token(T_FUNCTION), parentheses()->as('args'), braces()->as('body'))->as('function'), string()->as('string'), rtoken('/^T_\\w+·\\w+$/')->as('token'), rtoken('/^T_\\w+$/')->as('constant'), rtoken('/^·this$/')->as('this'), label()->as('label'))->as('parser'), token(',')))->as('args'), commit(token(')')), optional(rtoken('/^·\\w+$/')->as('label'), null)))->onCommit(function (Ast $result) use($cg) {
         $cg->parsers[] = $this->compileParser($result->type, $result->args, $result->label);
     }), $this->layer('{', '}', braces(), $cg), $this->layer('[', ']', brackets(), $cg), $this->layer('(', ')', parentheses(), $cg), rtoken('/^···(\\w+)$/')->onCommit(function (Ast $result) use($cg) {
         $id = $this->lookupCapture($result->token());
         $cg->parsers[] = layer()->as($id);
     }), token(T_STRING, '·')->onCommit(function (Ast $result) use($cg) {
         $offset = \count($cg->parsers);
         if (0 !== $this->dominance || 0 === $offset) {
             $this->fail(self::E_BAD_DOMINANCE, $offset, $result->token()->line());
         }
         $this->dominance = $offset;
     }), rtoken('/·/')->onCommit(function (Ast $result) {
         $token = $result->token();
         $this->fail(self::E_BAD_CAPTURE, $token, $token->line());
     }), any()->onCommit(function (Ast $result) use($cg) {
         $cg->parsers[] = token($result->token());
     }))->parse($cg->ts);
     // check if macro dominance '·' is last token
     if ($this->dominance === \count($cg->parsers)) {
         $this->fail(self::E_BAD_DOMINANCE, $this->dominance, $cg->ts->last()->line());
     }
     $this->specificity = \count($cg->parsers);
     if ($this->specificity > 1) {
         if (0 === $this->dominance) {
             $pattern = chain(...$cg->parsers);
         } else {
             /*
               dominat macros are partially wrapped in commit()s and dominance
               is the offset used as the 'event horizon' point... once the entry
               point is matched, there is no way back and a parser error arises
             */
             $prefix = array_slice($cg->parsers, 0, $this->dominance);
             $suffix = array_slice($cg->parsers, $this->dominance);
             $pattern = chain(...array_merge($prefix, array_map(commit::class, $suffix)));
         }
     } else {
         /*
           micro optimization to save one function call for every token on the subject
           token stream whenever the macro pattern consists of a single parser
         */
         $pattern = $cg->parsers[0];
     }
     return $pattern;
 }
开发者ID:lastguest,项目名称:yay,代码行数:52,代码来源:Pattern.php


示例10: fillFeed

 private function fillFeed(Feed $feed)
 {
     $posts = app(ContentRepository::class)->posts();
     $feed->title = 'Sebastian De Deyne';
     $feed->description = 'Full-stack developer working at Spatie in Antwerp, Belgium';
     $feed->link = request()->url();
     $feed->setDateFormat('datetime');
     $feed->pubdate = $posts->first() ? $posts->first()->date : Carbon::now();
     $feed->lang = 'en';
     $feed->setShortening(false);
     $posts->each(function (Article $post) use($feed) {
         $feed->add($post->title, 'Sebastian De Deyne', $post->url, $post->date, string($post->contents)->tease(140), $post->contents);
     });
 }
开发者ID:sebastiandedeyne,项目名称:sebastiandedeyne.com,代码行数:14,代码来源:FeedController.php


示例11: subscribe

 /**
  * @param \App\Http\Requests\Front\NewsletterSubscriptionRequest $request
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function subscribe(NewsletterSubscriptionRequest $request)
 {
     try {
         $this->newsletter->subscribe($request->get('email'));
         Activity::log($request->get('email') . ' schreef zich in op de nieuwsbrief.');
     } catch (AlreadySubscribed $exception) {
         return $this->respond(string('newsletter.subscription.result.alreadySubscribed'));
     } catch (ServiceRefusedSubscription $exception) {
         return $this->respondWithBadRequest(string('newsletter.subscription.result.error'));
     } catch (Exception $e) {
         Log::error('newsletter subscription failed with exception message: ' . $e->getMessage());
         return $this->respondWithInternalServerError(string('newsletter.subscription.result.error'));
     }
     return $this->respond(string('newsletter.subscription.result.ok'));
 }
开发者ID:bjrnblm,项目名称:blender,代码行数:20,代码来源:NewsletterApiController.php


示例12: up

 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::create('products', function (Blueprint $table) {
         $table->increments('id');
         $table->string('name');
         $table->string('reference');
         $table - mediumText('description');
         $table - string('inspection_points');
         $table - string('inspection');
         $table - string('classification');
         $table - string('existence');
         $table - string('enable', 5);
         $table->timestamps();
         $table->softDeletes();
     });
 }
开发者ID:alexlondon07,项目名称:pms_laravel5,代码行数:21,代码来源:2016_02_20_130056_create_products_table.php


示例13: isValid

 public function isValid($value, Constraint $constraint)
 {
     if (parent::isValid($value, $constraint)) {
         if ($value instanceof \DateTime) {
             $tm = $value->getTimestamp();
         } else {
             preg_match(self::PATTERN_BIRTHDAY, string($value), $matches);
             $tm = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
         }
         if (time() > $tm) {
             return true;
         }
         $this->setMessage($constraint->messageBirthday, array('{{ value }}' => $value));
     }
     return false;
 }
开发者ID:npotier,项目名称:AcseoExtraFormValidatorBundle,代码行数:16,代码来源:BirthDayValidator.php


示例14: _select

 /**
  * DB select query.
  *
  * @param   string|array    $cond
  * @param   string          $order
  * @param   integer         $count
  * @param   integer         $offset
  * @param   string|array    $cols
  * @return  array
  */
 protected function _select($cond = null, $order = null, $count = null, $offset = null, $cols = null)
 {
     $select = $this->_db->select();
     if (empty($cols)) {
         $cols = '*';
     }
     $select->from($this->_table, $cols);
     if ($cond) {
         if (is_array($cond)) {
             foreach ($cond as $field => $value) {
                 $select->where("{$field} = ?", $value);
             }
         } else {
             $select->where(string($cond));
         }
     }
     //end if
     $select->order($order);
     $select->limit($count, $offset);
     return $this->_db->fetchAll($select);
 }
开发者ID:BackupTheBerlios,项目名称:agileweb,代码行数:31,代码来源:DbDAO.php


示例15: addPostAction

 public function addPostAction(Request $request, Response $response)
 {
     if ($request->isPost()) {
         $data = $request->getParsedBody();
         $title = $data['post_title'];
         $slug = trim($title);
         $slug = str_replace(' ', '-', $slug);
         $alias = $data['post_alias'];
         $content = $data['post_data'];
         $id = string($data['cat']);
         $post = new Posts();
         $post->setAlias($alias);
         $post->setCategory($id);
         $post->setPublished(true);
         $post->setSlug($slug);
         $post->setContent($content);
         $this->em->persist($post);
         $this->em->flush();
     }
     $this->view->render($response, 'admin/post/newpost.html', ['post' => $post]);
     return $response;
 }
开发者ID:hak2c,项目名称:phamthanhha_net,代码行数:22,代码来源:PostController.php


示例16: GREATEST

$description = null;
$result = false;
if ($conn) {
    $title = $title_error = 'Whoops...';
    $pagetitle = $pagetitle_error = 'Page not found';
    // Old Webkit breaks the layout without </p>
    $content = $content_error = '<p>This page hasn\'t been found. Try to <a class=x-error href=' . $url . '>reload</a>' . ($ishome ? null : ' or head to <a href=' . $path . '>home page</a>') . '.</p>';
    $stmt = $mysqli->prepare('SELECT title, description, content, GREATEST(modified, created) AS date FROM `' . table . '` WHERE url=? LIMIT 1');
    $stmt->bind_param('s', $urldb);
    $stmt->execute();
    $stmt->bind_result($title, $description, $content, $date);
    while ($stmt->fetch()) {
        $result = true;
        // SEO page title improvement for the root page
        $pagetitle = $ishome ? $title : $gtitle;
        $content = string($content);
    }
    $stmt->free_result();
    $stmt->close();
    if (!$result) {
        // URL does not exist
        http_response_code(404);
        $title = $title_error;
        $content = $content_error;
        $pagetitle = $pagetitle_error;
    }
    if (isset($_GET['api'])) {
        // API
        include 'content/api.php';
        exit;
    }
开发者ID:rayrc,项目名称:ajax-seo,代码行数:31,代码来源:index.php


示例17: create

 function create($key, $replication_factor = 2, $overwrite = 'true')
 {
     $this->saveFile($key, string($replication_factor), $key);
 }
开发者ID:rshariffdeen,项目名称:olio,代码行数:4,代码来源:MogileFS.php


示例18: tease

 /**
  * @param string $characters
  * @param string $moreTextIndicator
  *
  * @return \Spatie\String\Str
  */
 public function tease($characters, $moreTextIndicator = '...')
 {
     return (string) string($this->entity->text)->tease($characters, $moreTextIndicator);
 }
开发者ID:bjrnblm,项目名称:blender,代码行数:10,代码来源:ArticlePresenter.php


示例19: excerpt

 /**
  *  Get an array with all possible types.
  *
  * @param int $length
  *
  * @return \Spatie\String\Str
  */
 public function excerpt($length = 200)
 {
     return string($this->entity->text)->tease($length);
 }
开发者ID:bjrnblm,项目名称:blender,代码行数:11,代码来源:NewsItemPresenter.php


示例20: count_attributes

function count_attributes($dir, $single_file = FALSE)
{
    $no_activity_dates = array();
    $activities_with_at_least_one = array();
    $no_activities = array();
    $found_hierarchies = array();
    $activities_with_attribute = array();
    $activity_by = array();
    $document_links = array();
    $result_element = array();
    $conditions = array();
    $participating_org_accountable = array();
    $participating_org_implementing = array();
    $budget = array();
    $identifiers = array();
    $transaction_type_commitment = array();
    $transaction_type_disbursement = array();
    $transaction_type_expenditure = array();
    $no_disbursements = $no_incoming_funds = $no_tracable_transactions = array();
    $activities_with_sector = array();
    $most_recent = array();
    $activities_with_location = array();
    $activities_with_coordinates = array();
    $activities_with_adminstrative = array();
    $activities_sector_assumed_dac = array();
    $activities_sector_declared_dac = array();
    $activies_in_country_lang = array();
    $i = 0;
    //used to count bad id's
    if ($handle = opendir($dir)) {
        //echo "Directory handle: $handle\n";
        //echo "Files:\n";
        /* This is the correct way to loop over the directory. */
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != "..") {
                //ignore these system files
                //echo $file . PHP_EOL;
                if ($single_file && $file != $single_file) {
                    //skip all files except the one we want if set/requested.Handy to test just one file in a directory
                    continue;
                }
                //load the xml SAFELY
                /* Some safety against XML Injection attack
                 * see: http://phpsecurity.readthedocs.org/en/latest/Injection-Attacks.html
                 * 
                 * Attempt a quickie detection of DOCTYPE - discard if it is present (cos it shouldn't be!)
                 */
                $xml = file_get_contents($dir . $file);
                $collapsedXML = preg_replace("/[[:space:]]/", '', $xml);
                //echo $collapsedXML;
                if (preg_match("/<!DOCTYPE/i", $collapsedXML)) {
                    //throw new InvalidArgumentException(
                    //     'Invalid XML: Detected use of illegal DOCTYPE'
                    // );
                    //echo "fail";
                    return FALSE;
                }
                $loadEntities = libxml_disable_entity_loader(true);
                $dom = new DOMDocument();
                $dom->loadXML($xml);
                foreach ($dom->childNodes as $child) {
                    if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
                        throw new Exception\ValueException('Invalid XML: Detected use of illegal DOCTYPE');
                        libxml_disable_entity_loader($loadEntities);
                        return FALSE;
                    }
                }
                libxml_disable_entity_loader($loadEntities);
                if ($xml = simplexml_import_dom($dom)) {
                    //print_r($xml);
                    if (!xml_child_exists($xml, "//iati-organisation")) {
                        //exclude organisation files
                        $activities = $xml->{"iati-activity"};
                        //print_r($attributes); die;
                        foreach ($activities as $activity) {
                            $hierarchy = (string) $activity->attributes()->hierarchy;
                            if ($hierarchy && $hierarchy != NULL) {
                                $hierarchy = (string) $activity->attributes()->hierarchy;
                            } else {
                                $hierarchy = 0;
                            }
                            $found_hierarchies[] = $hierarchy;
                            if (!isset($no_activities[$hierarchy])) {
                                $no_activities[$hierarchy] = 0;
                            }
                            $no_activities[$hierarchy]++;
                            //Set up some more counters:
                            if (!isset($no_disbursements[$hierarchy])) {
                                $no_disbursements[$hierarchy] = 0;
                            }
                            if (!isset($no_incoming_funds[$hierarchy])) {
                                $no_incoming_funds[$hierarchy] = 0;
                            }
                            if (!isset($no_tracable_transactions[$hierarchy])) {
                                $no_tracable_transactions[$hierarchy] = 0;
                            }
                            //Elements check
                            //is <document-link>,<conditions>,<result> present
                            if (count($activity->{"document-link"}) > 0) {
                                $document_links[$hierarchy][] = (string) $activity->{'iati-identifier'};
//.........这里部分代码省略.........
开发者ID:rolfkleef,项目名称:IATI-Public-Validator,代码行数:101,代码来源:transparency_calculations.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP string2array函数代码示例发布时间:2022-05-23
下一篇:
PHP strim函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap