本文整理汇总了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('/'));
}
示例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;
}
示例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]);
}
}
示例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()]);
});
}
示例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);
}
示例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;
}
示例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');
}
示例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;
}
示例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;
}
示例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);
});
}
示例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'));
}
示例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();
});
}
示例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;
}
示例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);
}
示例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;
}