Skip to content

Commit 744618d

Browse files
committed
Releasing 1.1.19
2 parents a7ffbdc + 6f933ec commit 744618d

3 files changed

Lines changed: 52 additions & 8 deletions

File tree

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
],
1515
"require" : {
1616
"php" : ">=7.0.0",
17+
"ext-mbstring" : "*",
1718
"technicalguru/i18n" : "~1"
1819
},
1920
"autoload" : {

src/TgUtils/Html.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,22 @@ class Html {
99

1010
/**
1111
* Returns the opening tag with the given attributes.
12-
* @param string $tagName - the name of the tag
12+
* @param string $tagName - the name of the tag
1313
* @param array $attributes - the attributes to be rendered (values will be encoded accordingly)
14+
* @param array $closeTag - close the tag immediately by including the slash, e.g. <br/>
1415
* @return string the opening HTML tag rendered
1516
*/
16-
public static function renderStartTag($tagName, $attributes = array()) {
17+
public static function renderStartTag($tagName, $attributes = array(), $closeTag = FALSE) {
1718
$rc = '<'.$tagName;
18-
foreach ($attributes AS $name => $value) {
19-
if (is_array($value)) $value = implode(' ', $value);
20-
if (is_string($value) && trim($value) != '') {
21-
$rc .= ' '.$name.'="'.htmlspecialchars($value).'"';
19+
if (is_array($attributes)) {
20+
foreach ($attributes AS $name => $value) {
21+
if (is_array($value)) $value = implode(' ', $value);
22+
if (is_string($value) && trim($value) != '') {
23+
$rc .= ' '.$name.'="'.htmlspecialchars($value).'"';
24+
}
2225
}
2326
}
24-
27+
if ($closeTag) $rc .= '/';
2528
$rc .= '>';
2629
return $rc;
2730
}
@@ -34,4 +37,4 @@ public static function renderStartTag($tagName, $attributes = array()) {
3437
public static function renderEndTag($tagName) {
3538
return '</'.$tagName. '>';
3639
}
37-
}
40+
}

src/TgUtils/Utils.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,46 @@ public static function isEmail($s) {
130130
return filter_var($s, FILTER_VALIDATE_EMAIL);
131131
}
132132

133+
/**
134+
* NULL-safe startsWith test for strings.
135+
* @return boolean TRUE when the test succeeds, FALSE if any argument is NULL or test failed.
136+
*/
137+
public static function startsWith($haystack, $needle, $ignoreCase = FALSE) {
138+
if (($haystack == NULL) || ($needle == NULL)) return FALSE;
139+
if ($ignoreCase) {
140+
$haystack = mb_strtolower($haystack);
141+
$needle = mb_strtolower($needle);
142+
}
143+
return mb_strpos($haystack, $needle) === 0;
144+
}
145+
146+
/**
147+
* NULL-safe endsWith test for strings.
148+
* @return boolean TRUE when the test succeeds, FALSE if any argument is NULL or test failed.
149+
*/
150+
public static function endsWith($haystack, $needle, $ignoreCase = FALSE) {
151+
if (($haystack == NULL) || ($needle == NULL)) return FALSE;
152+
if ($ignoreCase) {
153+
$haystack = mb_strtolower($haystack);
154+
$needle = mb_strtolower($needle);
155+
}
156+
return mb_strpos($haystack, $needle) == mb_strlen($haystack)-mb_strlen($needle);
157+
}
158+
159+
/**
160+
* NULL-safe contains test for strings.
161+
* @return boolean TRUE when the test succeeds, FALSE if any argument is NULL or test failed.
162+
*/
163+
public static function contains($haystack, $needle, $ignoreCase = FALSE) {
164+
if (($haystack == NULL) || ($needle == NULL)) return FALSE;
165+
if ($ignoreCase) {
166+
$haystack = mb_strtolower($haystack);
167+
$needle = mb_strtolower($needle);
168+
}
169+
return mb_strpos($haystack, $needle) !== FALSE;
170+
}
171+
172+
/**
133173
/**
134174
* Checks whether an array is associative or not.
135175
* @param array $arr - the array to be tested

0 commit comments

Comments
 (0)