-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1796699
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
namespace Onvardgmbh\HelperClasses; | ||
|
||
class Link { | ||
|
||
/** | ||
* ASCII escape a string. | ||
* Can be used to obfuscate email addresses. | ||
* | ||
* @since 0.0.1 | ||
* @author André Schwarzer <[email protected]> | ||
* | ||
* @param String $string | ||
* | ||
* @return String | ||
*/ | ||
public static function asciiEscString( $string ) { | ||
$return = ''; | ||
foreach ( str_split( $string ) as $char ) { | ||
$return .= '&#' . ord( $char ) . ';'; | ||
} | ||
|
||
return $return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
namespace Onvardgmbh\HelperClasses; | ||
|
||
class Text { | ||
|
||
/** | ||
* Unicode safe version of substr_replace | ||
* | ||
* @since 0.0.1 | ||
* | ||
* @link http://php.net/manual/de/function.substr-replace.php Taken from comment in PHP docs | ||
* | ||
* @param String $string | ||
* | ||
* @return String | ||
*/ | ||
public static function mb_substr_replace( $string, $replacement, $start, $length = null, $encoding = null ) { | ||
|
||
if ( extension_loaded( 'mbstring' ) === true ) { | ||
$string_length = ( is_null( $encoding ) === true ) ? mb_strlen( $string ) : mb_strlen( $string, $encoding ); | ||
|
||
if ( $start < 0 ) { | ||
$start = max( 0, $string_length + $start ); | ||
} else if ( $start > $string_length ) { | ||
$start = $string_length; | ||
} | ||
|
||
if ( $length < 0 ) { | ||
$length = max( 0, $string_length - $start + $length ); | ||
} else if ( ( is_null( $length ) === true ) || ( $length > $string_length ) ) { | ||
$length = $string_length; | ||
} | ||
|
||
if ( ( $start + $length ) > $string_length ) { | ||
$length = $string_length - $start; | ||
} | ||
|
||
if ( is_null( $encoding ) === true ) { | ||
return mb_substr( $string, 0, $start ) . $replacement . mb_substr( $string, $start + $length, | ||
$string_length - $start - $length ); | ||
} | ||
|
||
return mb_substr( $string, 0, $start, $encoding ) . $replacement . mb_substr( $string, $start + $length, | ||
$string_length - $start - $length, $encoding ); | ||
} | ||
|
||
return ( is_null( $length ) === true ) ? substr_replace( $string, $replacement, | ||
$start ) : substr_replace( $string, $replacement, $start, $length ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "onvardgmbh/helper-classes", | ||
"description": "PHP Helper Classes for often used functions", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Björn Hasse", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": {}, | ||
"autoload": { | ||
"psr-4": { | ||
"Onvardgmbh\\HelperClasses\\": "/" | ||
} | ||
} | ||
} |
Empty file.