Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
3c05f726
Commit
3c05f726
authored
Sep 29, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring string class.
parent
442904b2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
29 deletions
+55
-29
core.php
laravel/bootstrap/core.php
+5
-0
str.php
laravel/str.php
+50
-29
No files found.
laravel/bootstrap/core.php
View file @
3c05f726
...
...
@@ -63,3 +63,8 @@ function __($key, $replacements = array(), $language = null)
{
return
Lang
::
line
(
$key
,
$replacements
,
$language
);
}
function
fe
(
$function
)
{
return
function_exists
(
$function
);
}
\ No newline at end of file
laravel/str.php
View file @
3c05f726
...
...
@@ -5,78 +5,93 @@ class Str {
/**
* Convert a string to lowercase.
*
* <code>
* // Convert a string to lowercase
* echo Str::lower('STOP YELLING');
*
* // Convert a UTF-8 string to lowercase
* echo Str::lower('Τάχιστη');
* </code>
*
* @param string $value
* @return string
*/
public
static
function
lower
(
$value
)
{
if
(
function_exists
(
'mb_strtolower'
))
{
return
mb_strtolower
(
$value
,
Config
::
get
(
'application.encoding'
));
}
return
strtolower
(
$value
);
return
(
fe
(
'mb_strtolower'
))
?
mb_strtolower
(
$value
,
Config
::
get
(
'application.encoding'
))
:
strtolower
(
$value
);
}
/**
* Convert a string to uppercase.
*
* <code>
* // Convert a string to uppercase
* echo Str::upper('speak louder');
*
* // Convert a UTF-8 string to uppercase
* echo Str::upper('Τάχιστη');
* </code>
*
* @param string $value
* @return string
*/
public
static
function
upper
(
$value
)
{
if
(
function_exists
(
'mb_strtoupper'
))
{
return
mb_strtoupper
(
$value
,
Config
::
get
(
'application.encoding'
));
}
return
strtoupper
(
$value
);
return
(
fe
(
'mb_strtoupper'
))
?
mb_strtoupper
(
$value
,
Config
::
get
(
'application.encoding'
))
:
strtoupper
(
$value
);
}
/**
* Convert a string to title case (ucwords).
* Convert a string to title case (ucwords equivalent).
*
* <code>
* // Convert a string to title case
* echo Str::title('taylor otwell');
*
* // Convert a UTF-8 string to title case
* echo Str::title('Τάχιστη αλώπηξ');
* </code>
*
* @param string $value
* @return string
*/
public
static
function
title
(
$value
)
{
if
(
function_exists
(
'mb_convert_case'
))
{
return
mb_convert_case
(
$value
,
MB_CASE_TITLE
,
Config
::
get
(
'application.encoding'
));
}
return
ucwords
(
strtolower
(
$value
));
return
(
fe
(
'mb_convert_case'
))
?
mb_convert_case
(
$value
,
MB_CASE_TITLE
,
Config
::
get
(
'application.encoding'
))
:
ucwords
(
strtolower
(
$value
));
}
/**
* Get the length of a string.
*
* <code>
* // Get the length of a string
* echo Str::length('taylor otwell');
*
* // Get the length of a UTF-8 string
* echo Str::length('Τάχιστη αλώπηξ');
* </code>
*
* @param string $value
* @return int
*/
public
static
function
length
(
$value
)
{
if
(
function_exists
(
'mb_strlen'
))
{
return
mb_strlen
(
$value
,
Config
::
get
(
'application.encoding'
));
}
return
strlen
(
$value
);
return
(
fe
(
'mb_strlen'
))
?
mb_strlen
(
$value
,
Config
::
get
(
'application.encoding'
))
:
strlen
(
$value
);
}
/**
* Convert a string to 7-bit ASCII.
*
* <code>
* // Returns "Deuxieme Article"
* echo Str::ascii('Deuxième Article');
* </code>
*
* @param string $value
* @return string
*/
public
static
function
ascii
(
$value
)
{
$foreign
=
Config
::
get
(
'ascii'
);
$value
=
preg_replace
(
array_keys
(
$foreign
),
array_values
(
$foreign
),
$value
);
$value
=
preg_replace
(
array_keys
(
$foreign
=
Config
::
get
(
'ascii'
)),
array_values
(
$foreign
),
$value
);
return
preg_replace
(
'/[^\x09\x0A\x0D\x20-\x7E]/'
,
''
,
$value
);
}
...
...
@@ -84,7 +99,13 @@ class Str {
/**
* Generate a random alpha or alpha-numeric string.
*
* Supported types: 'alnum' and 'alpha'.
* <code>
* // Generate a 40 character random, alpha-numeric string
* echo Str::random(40);
*
* // Generate a 16 character random, alphabetic string
* echo Str::random(16, 'alpha');
* <code>
*
* @param int $length
* @param string $type
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment