Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoernhasse committed Oct 12, 2016
0 parents commit 1796699
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Link.php
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;
}
}
50 changes: 50 additions & 0 deletions Text.php
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 );
}
}
17 changes: 17 additions & 0 deletions composer.json
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 added readme.md
Empty file.

0 comments on commit 1796699

Please sign in to comment.