| Server IP : 146.59.209.152 / Your IP : 216.73.216.46 Web Server : Apache System : Linux webm005.cluster131.gra.hosting.ovh.net 5.15.167-ovh-vps-grsec-zfs-classid #1 SMP Tue Sep 17 08:14:20 UTC 2024 x86_64 User : infrafs ( 43850) PHP Version : 8.2.29 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/infrafs/www/wp-content/plugins/duplicator/lib/snaplib/ |
Upload File : |
<?php
/**
* Snap strings utils
*
* Standard: PSR-2
* @link http://www.php-fig.org/psr/psr-2
*
* @package DupLiteSnapLib
* @copyright (c) 2017, Snapcreek LLC
* @license https://opensource.org/licenses/GPL-3.0 GNU Public License
*
*/
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
if (!class_exists('DupLiteSnapLibStringU', false)) {
class DupLiteSnapLibStringU
{
public static function boolToString($b)
{
return ($b ? 'true' : 'false');
}
public static function truncateString($s, $maxWidth)
{
if (strlen($s) > $maxWidth) {
$s = substr($s, 0, $maxWidth - 3).'...';
}
return $s;
}
/**
* Returns true if the $haystack string starts with the $needle
*
* @param string $haystack The full string to search in
* @param string $needle The string to for
*
* @return bool Returns true if the $haystack string starts with the $needle
*/
public static function startsWith($haystack, $needle)
{
$length = strlen($needle);
return (substr($haystack, 0, $length) === $needle);
}
/**
* Returns true if the $haystack string end with the $needle
*
* @param string $haystack The full string to search in
* @param string $needle The string to for
*
* @return bool Returns true if the $haystack string starts with the $needle
*/
public static function endsWith($haystack, $needle)
{
$length = strlen($needle);
if ($length == 0) {
return true;
}
return (substr($haystack, -$length) === $needle);
}
/**
* Returns true if the $needle is found in the $haystack
*
* @param string $haystack The full string to search in
* @param string $needle The string to for
*
* @return bool
*/
public static function contains($haystack, $needle)
{
$pos = strpos($haystack, $needle);
return ($pos !== false);
}
/**
*
* @param string $glue
* @param array $pieces
* @param string $format
* @return string
*/
public static function implodeKeyVals($glue, $pieces, $format = '%s="%s"')
{
$strList = array();
foreach ($pieces as $key => $value) {
if (is_scalar($value)) {
$strList[] = sprintf($format, $key, $value);
} else {
$strList[] = sprintf($format, $key, print_r($value, true));
}
}
return implode($glue, $strList);
}
/**
* Replace last occurrence
*
* @param String $search The value being searched for
* @param String $replace The replacement value that replaces found search values
* @param String $str The string or array being searched and replaced on, otherwise known as the haystack
* @param Boolean $caseSensitive Whether the replacement should be case sensitive or not
*
* @return String
*/
public static function strLastReplace($search, $replace, $str, $caseSensitive = true)
{
$pos = $caseSensitive ? strrpos($str, $search) : strripos($str, $search);
if (false !== $pos) {
$str = substr_replace($str, $replace, $pos, strlen($search));
}
return $str;
}
/**
*
* @param string $string
* @return boolean
*/
public static function isHTML($string)
{
return ($string != strip_tags($string));
}
}
}