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


PHP string函数代码示例

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


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


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