Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dokuwiki
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BRIC
dokuwiki
Commits
2f954959
Commit
2f954959
authored
20 years ago
by
andi
Browse files
Options
Downloads
Patches
Plain Diff
utf8 replacements for strpos and strlen
darcs-hash:20050123155239-9977f-2ddc1e19ccf48579c71382e8933166a86ee750a4.gz
parent
f29bd553
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
inc/utf8.php
+52
-0
52 additions, 0 deletions
inc/utf8.php
with
52 additions
and
0 deletions
inc/utf8.php
+
52
−
0
View file @
2f954959
...
...
@@ -52,6 +52,24 @@ function utf8_check($Str) {
return
true
;
}
/**
* This is a unicode aware replacement for strlen()
*
* Uses mb_string extension if available
*
* @author Andreas Gohr <andi@splitbrain.org>
* @see strlen()
*/
function
utf8_strlen
(
$string
){
if
(
!
defined
(
'UTF8_NOMBSTRING'
)
&&
function_exists
(
'mb_strlen'
))
return
mb_strlen
(
$string
,
'utf-8'
);
$uni
=
utf8_to_unicode
(
$string
);
return
count
(
$uni
);
}
/**
* This is a unicode aware replacement for strtolower()
*
...
...
@@ -118,6 +136,40 @@ function utf8_deaccent($string,$case=0){
return
$string
;
}
/**
* This is an Unicode aware replacement for strpos
*
* Uses mb_string extension if available
*
* @author Scott Michael Reynen <scott@randomchaos.com>
* @author Andreas Gohr <andi@splitbrain.org>
* @link http://www.randomchaos.com/document.php?source=php_and_unicode
* @see strpos()
*/
function
utf8_strpos
(
$haystack
,
$needle
,
$offset
=
0
)
{
if
(
!
defined
(
'UTF8_NOMBSTRING'
)
&&
function_exists
(
'mb_strpos'
))
return
mb_strpos
(
$haystack
,
$needle
,
$offset
,
'utf-8'
);
$haystack
=
utf8_to_unicode
(
$haystack
);
$needle
=
utf8_to_unicode
(
$needle
);
$position
=
$offset
;
$found
=
false
;
while
(
(
!
$found
)
&&
(
$position
<
count
(
$haystack
)
)
)
{
if
(
$needle
[
0
]
==
$haystack
[
$position
]
)
{
for
(
$i
=
1
;
$i
<
count
(
$needle
);
$i
++
)
{
if
(
$needle
[
$i
]
!=
$haystack
[
$position
+
$i
]
)
break
;
}
if
(
$i
==
count
(
$needle
)
)
{
$found
=
true
;
$position
--
;
}
}
$position
++
;
}
return
(
$found
==
true
)
?
$position
:
false
;
}
/**
* This function will any UTF-8 encoded text and return it as
* a list of Unicode values:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment