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
Hide 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
...
@@ -62,4 +62,9 @@ function e($value)
...
@@ -62,4 +62,9 @@ function e($value)
function
__
(
$key
,
$replacements
=
array
(),
$language
=
null
)
function
__
(
$key
,
$replacements
=
array
(),
$language
=
null
)
{
{
return
Lang
::
line
(
$key
,
$replacements
,
$language
);
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 {
...
@@ -5,78 +5,93 @@ class Str {
/**
/**
* Convert a string to lowercase.
* 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
* @param string $value
* @return string
* @return string
*/
*/
public
static
function
lower
(
$value
)
public
static
function
lower
(
$value
)
{
{
if
(
function_exists
(
'mb_strtolower'
))
return
(
fe
(
'mb_strtolower'
))
?
mb_strtolower
(
$value
,
Config
::
get
(
'application.encoding'
))
:
strtolower
(
$value
);
{
return
mb_strtolower
(
$value
,
Config
::
get
(
'application.encoding'
));
}
return
strtolower
(
$value
);
}
}
/**
/**
* Convert a string to uppercase.
* 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
* @param string $value
* @return string
* @return string
*/
*/
public
static
function
upper
(
$value
)
public
static
function
upper
(
$value
)
{
{
if
(
function_exists
(
'mb_strtoupper'
))
return
(
fe
(
'mb_strtoupper'
))
?
mb_strtoupper
(
$value
,
Config
::
get
(
'application.encoding'
))
:
strtoupper
(
$value
);
{
return
mb_strtoupper
(
$value
,
Config
::
get
(
'application.encoding'
));
}
return
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
* @param string $value
* @return string
* @return string
*/
*/
public
static
function
title
(
$value
)
public
static
function
title
(
$value
)
{
{
if
(
function_exists
(
'mb_convert_case'
))
return
(
fe
(
'mb_convert_case'
))
?
mb_convert_case
(
$value
,
MB_CASE_TITLE
,
Config
::
get
(
'application.encoding'
))
:
ucwords
(
strtolower
(
$value
));
{
return
mb_convert_case
(
$value
,
MB_CASE_TITLE
,
Config
::
get
(
'application.encoding'
));
}
return
ucwords
(
strtolower
(
$value
));
}
}
/**
/**
* Get the length of a string.
* 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
* @param string $value
* @return int
* @return int
*/
*/
public
static
function
length
(
$value
)
public
static
function
length
(
$value
)
{
{
if
(
function_exists
(
'mb_strlen'
))
return
(
fe
(
'mb_strlen'
))
?
mb_strlen
(
$value
,
Config
::
get
(
'application.encoding'
))
:
strlen
(
$value
);
{
return
mb_strlen
(
$value
,
Config
::
get
(
'application.encoding'
));
}
return
strlen
(
$value
);
}
}
/**
/**
* Convert a string to 7-bit ASCII.
* Convert a string to 7-bit ASCII.
*
*
* <code>
* // Returns "Deuxieme Article"
* echo Str::ascii('Deuxième Article');
* </code>
*
* @param string $value
* @param string $value
* @return string
* @return string
*/
*/
public
static
function
ascii
(
$value
)
public
static
function
ascii
(
$value
)
{
{
$foreign
=
Config
::
get
(
'ascii'
);
$value
=
preg_replace
(
array_keys
(
$foreign
=
Config
::
get
(
'ascii'
)),
array_values
(
$foreign
),
$value
);
$value
=
preg_replace
(
array_keys
(
$foreign
),
array_values
(
$foreign
),
$value
);
return
preg_replace
(
'/[^\x09\x0A\x0D\x20-\x7E]/'
,
''
,
$value
);
return
preg_replace
(
'/[^\x09\x0A\x0D\x20-\x7E]/'
,
''
,
$value
);
}
}
...
@@ -84,7 +99,13 @@ class Str {
...
@@ -84,7 +99,13 @@ class Str {
/**
/**
* Generate a random alpha or alpha-numeric string.
* 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 int $length
* @param string $type
* @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