Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
meibuyu-micro
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
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
without authentication
meibuyu-micro
Commits
2d3435c1
Commit
2d3435c1
authored
Sep 11, 2020
by
王源
🎧
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加用替换字符串替换第一个出现的搜索字符串全局方法
parent
8d2272dc
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
0 deletions
+20
-0
functions.php
src/functions.php
+20
-0
No files found.
src/functions.php
View file @
2d3435c1
...
@@ -759,6 +759,7 @@ if (!function_exists('mb_trim')) {
...
@@ -759,6 +759,7 @@ if (!function_exists('mb_trim')) {
* 去除两边带全角空格的字符串
* 去除两边带全角空格的字符串
* @param $str
* @param $str
* @return string
* @return string
* @author zero
*/
*/
function
mb_trim
(
$str
)
function
mb_trim
(
$str
)
{
{
...
@@ -767,3 +768,22 @@ if (!function_exists('mb_trim')) {
...
@@ -767,3 +768,22 @@ if (!function_exists('mb_trim')) {
return
trim
(
$str
);
return
trim
(
$str
);
}
}
}
}
if
(
!
function_exists
(
'str_replace_once'
))
{
/**
* 用替换字符串替换第一个出现的搜索字符串
* @param mixed $search 搜索字符串
* @param mixed $replace 替换字符串
* @param mixed $subject 被替换字符串
* @return string
* @author zero
*/
function
str_replace_first
(
$search
,
$replace
,
$subject
)
{
if
((
$position
=
strpos
(
$subject
,
$search
))
!==
false
)
{
$replaceLen
=
strlen
(
$search
);
$subject
=
substr_replace
(
$subject
,
$replace
,
$position
,
$replaceLen
);
}
return
$subject
;
}
}
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