Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
UserAdminV2
Overview
Overview
Details
Activity
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
庄欣
UserAdminV2
Commits
c50246c6
Commit
c50246c6
authored
Jul 07, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring Str class.
parent
607b23b7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
21 deletions
+24
-21
system/str.php
+24
-21
No files found.
system/str.php
View file @
c50246c6
...
...
@@ -70,28 +70,8 @@ class Str {
{
$value
=
''
;
// -----------------------------------------------------
// Get the proper character pool for the type.
// -----------------------------------------------------
switch
(
$type
)
{
case
'alpha'
:
$pool
=
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
;
break
;
default
:
$pool
=
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
;
}
$pool_length
=
strlen
(
$pool
=
static
::
pool
(
$type
))
-
1
;
// -----------------------------------------------------
// Get the pool length and split the pool into an array.
// -----------------------------------------------------
$pool_length
=
strlen
(
$pool
)
-
1
;
$pool
=
str_split
(
$pool
,
1
);
// -----------------------------------------------------
// Build the random string to the specified length.
// -----------------------------------------------------
for
(
$i
=
0
;
$i
<
$length
;
$i
++
)
{
$value
.=
$pool
[
mt_rand
(
0
,
$pool_length
)];
...
...
@@ -100,4 +80,26 @@ class Str {
return
$value
;
}
/**
* Get a chracter pool.
*
* @param string $type
* @return string
*/
private
static
function
pool
(
$type
=
'alnum'
)
{
if
(
$type
==
'alnum'
)
{
return
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
;
}
elseif
(
$type
==
'alpha'
)
{
return
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
;
}
else
{
throw
new
\Exception
(
"Unrecognized random pool [
$type
]."
);
}
}
}
\ No newline at end of file
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