Skip to content

Commit 1796699

Browse files
committed
Initial commit
0 parents  commit 1796699

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed

Link.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
namespace Onvardgmbh\HelperClasses;
3+
4+
class Link {
5+
6+
/**
7+
* ASCII escape a string.
8+
* Can be used to obfuscate email addresses.
9+
*
10+
* @since 0.0.1
11+
* @author André Schwarzer <[email protected]>
12+
*
13+
* @param String $string
14+
*
15+
* @return String
16+
*/
17+
public static function asciiEscString( $string ) {
18+
$return = '';
19+
foreach ( str_split( $string ) as $char ) {
20+
$return .= '&#' . ord( $char ) . ';';
21+
}
22+
23+
return $return;
24+
}
25+
}

Text.php

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
namespace Onvardgmbh\HelperClasses;
3+
4+
class Text {
5+
6+
/**
7+
* Unicode safe version of substr_replace
8+
*
9+
* @since 0.0.1
10+
*
11+
* @link http://php.net/manual/de/function.substr-replace.php Taken from comment in PHP docs
12+
*
13+
* @param String $string
14+
*
15+
* @return String
16+
*/
17+
public static function mb_substr_replace( $string, $replacement, $start, $length = null, $encoding = null ) {
18+
19+
if ( extension_loaded( 'mbstring' ) === true ) {
20+
$string_length = ( is_null( $encoding ) === true ) ? mb_strlen( $string ) : mb_strlen( $string, $encoding );
21+
22+
if ( $start < 0 ) {
23+
$start = max( 0, $string_length + $start );
24+
} else if ( $start > $string_length ) {
25+
$start = $string_length;
26+
}
27+
28+
if ( $length < 0 ) {
29+
$length = max( 0, $string_length - $start + $length );
30+
} else if ( ( is_null( $length ) === true ) || ( $length > $string_length ) ) {
31+
$length = $string_length;
32+
}
33+
34+
if ( ( $start + $length ) > $string_length ) {
35+
$length = $string_length - $start;
36+
}
37+
38+
if ( is_null( $encoding ) === true ) {
39+
return mb_substr( $string, 0, $start ) . $replacement . mb_substr( $string, $start + $length,
40+
$string_length - $start - $length );
41+
}
42+
43+
return mb_substr( $string, 0, $start, $encoding ) . $replacement . mb_substr( $string, $start + $length,
44+
$string_length - $start - $length, $encoding );
45+
}
46+
47+
return ( is_null( $length ) === true ) ? substr_replace( $string, $replacement,
48+
$start ) : substr_replace( $string, $replacement, $start, $length );
49+
}
50+
}

composer.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "onvardgmbh/helper-classes",
3+
"description": "PHP Helper Classes for often used functions",
4+
"license": "MIT",
5+
"authors": [
6+
{
7+
"name": "Björn Hasse",
8+
"email": "[email protected]"
9+
}
10+
],
11+
"require": {},
12+
"autoload": {
13+
"psr-4": {
14+
"Onvardgmbh\\HelperClasses\\": "/"
15+
}
16+
}
17+
}

readme.md

Whitespace-only changes.

0 commit comments

Comments
 (0)