phpMv  -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
JString.php
Go to the documentation of this file.
1 <?php
2 namespace Ajax\service;
3 
4 class JString {
5 
6  public static function contains($hay, $needle) {
7  return strpos($hay, "$needle") !== false;
8  }
9 
10  public static function startswith($hay, $needle) {
11  return substr($hay, 0, strlen($needle)) === $needle;
12  }
13 
14  public static function endswith($hay, $needle) {
15  return substr($hay, - strlen($needle)) === $needle;
16  }
17 
18  public static function isNull($s) {
19  return (! isset($s) || NULL === $s || "" === $s);
20  }
21 
22  public static function isNotNull($s) {
23  return (isset($s) && NULL !== $s && "" !== $s);
24  }
25 
26  public static function isBoolean($value) {
27  return \is_bool($value) || $value == 1 || $value == 0;
28  }
29 
30  public static function isBooleanTrue($value) {
31  return $value == 1 || $value;
32  }
33 
34  public static function isBooleanFalse($value) {
35  return $value == 0 || ! $value;
36  }
37 
38  public static function camelCaseToSeparated($input, $separator = " ") {
39  return strtolower(preg_replace('/(?<!^)[A-Z]/', $separator . '$0', $input));
40  }
41 
42  public static function replaceAtFirst($subject, $from, $to) {
43  $from = '/\A' . preg_quote($from, '/') . '/';
44  return \preg_replace($from, $to, $subject, 1);
45  }
46 
47  public static function replaceAtLast($subject, $from, $to) {
48  $from = '/' . preg_quote($from, '/') . '\z/';
49  return \preg_replace($from, $to, $subject, 1);
50  }
51 
52  public static function replaceAtFirstAndLast($subject, $fromFirst, $toFirst, $fromLast, $toLast) {
53  $s = self::replaceAtFirst($subject, $fromFirst, $toFirst);
54  return self::replaceAtLast($s, $fromLast, $toLast);
55  }
56 
57  public static function getValueBetween(&$str, $before = "{{", $after = "}}") {
58  $matches = [];
59  $result = null;
60  $_before = \preg_quote($before);
61  $_after = \preg_quote($after);
62  if (\preg_match('/' . $_before . '(.*?)' . $_after . '/s', $str, $matches) === 1) {
63  $result = $matches[1];
64  $str = \str_replace($before . $result . $after, "", $str);
65  }
66  return $result;
67  }
68 
69  public static function doubleBackSlashes($value) {
70  if (\is_string($value))
71  return \str_replace("\\", "\\\\", $value);
72  return $value;
73  }
74 
75  public static function cleanIdentifier($id) {
76  return \preg_replace('/[^a-zA-Z0-9\-\_]/s', '', $id);
77  }
78 }
static doubleBackSlashes($value)
Definition: JString.php:69
static isBoolean($value)
Definition: JString.php:26
static getValueBetween(&$str, $before="{{", $after="}}")
Definition: JString.php:57
static replaceAtFirstAndLast($subject, $fromFirst, $toFirst, $fromLast, $toLast)
Definition: JString.php:52
static isNotNull($s)
Definition: JString.php:22
static startswith($hay, $needle)
Definition: JString.php:10
static endswith($hay, $needle)
Definition: JString.php:14
static contains($hay, $needle)
Definition: JString.php:6
static camelCaseToSeparated($input, $separator=" ")
Definition: JString.php:38
static isBooleanFalse($value)
Definition: JString.php:34
static isBooleanTrue($value)
Definition: JString.php:30
static isNull($s)
Definition: JString.php:18
static replaceAtFirst($subject, $from, $to)
Definition: JString.php:42
static cleanIdentifier($id)
Definition: JString.php:75
static replaceAtLast($subject, $from, $to)
Definition: JString.php:47