aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/Utils.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2016-10-12 13:58:35 +0200
committerArthurHoaro <arthur@hoa.ro>2016-10-12 13:58:35 +0200
commitbc22c9a0acb095970e9494cbe8954f0612e05dc0 (patch)
tree4e3a94b7469f5b2e3eaf946756235730429bf9d4 /application/Utils.php
parent890afc32f744859d11b97eb26ed5c030af9b4145 (diff)
parentebd67c6e1b40aebdd3a52285ce9ff9412b2a3038 (diff)
downloadShaarli-bc22c9a0acb095970e9494cbe8954f0612e05dc0.tar.gz
Shaarli-bc22c9a0acb095970e9494cbe8954f0612e05dc0.tar.zst
Shaarli-bc22c9a0acb095970e9494cbe8954f0612e05dc0.zip
Merge tag 'v0.7.0' of github.com:shaarli/Shaarli into stable
Release v0.7.0
Diffstat (limited to 'application/Utils.php')
-rw-r--r--application/Utils.php32
1 files changed, 26 insertions, 6 deletions
diff --git a/application/Utils.php b/application/Utils.php
index 3d819716..da521cce 100644
--- a/application/Utils.php
+++ b/application/Utils.php
@@ -41,8 +41,14 @@ function smallHash($text)
41 41
42/** 42/**
43 * Tells if a string start with a substring 43 * Tells if a string start with a substring
44 *
45 * @param string $haystack Given string.
46 * @param string $needle String to search at the beginning of $haystack.
47 * @param bool $case Case sensitive.
48 *
49 * @return bool True if $haystack starts with $needle.
44 */ 50 */
45function startsWith($haystack, $needle, $case=true) 51function startsWith($haystack, $needle, $case = true)
46{ 52{
47 if ($case) { 53 if ($case) {
48 return (strcmp(substr($haystack, 0, strlen($needle)), $needle) === 0); 54 return (strcmp(substr($haystack, 0, strlen($needle)), $needle) === 0);
@@ -52,8 +58,14 @@ function startsWith($haystack, $needle, $case=true)
52 58
53/** 59/**
54 * Tells if a string ends with a substring 60 * Tells if a string ends with a substring
61 *
62 * @param string $haystack Given string.
63 * @param string $needle String to search at the end of $haystack.
64 * @param bool $case Case sensitive.
65 *
66 * @return bool True if $haystack ends with $needle.
55 */ 67 */
56function endsWith($haystack, $needle, $case=true) 68function endsWith($haystack, $needle, $case = true)
57{ 69{
58 if ($case) { 70 if ($case) {
59 return (strcmp(substr($haystack, strlen($haystack) - strlen($needle)), $needle) === 0); 71 return (strcmp(substr($haystack, strlen($haystack) - strlen($needle)), $needle) === 0);
@@ -63,14 +75,22 @@ function endsWith($haystack, $needle, $case=true)
63 75
64/** 76/**
65 * Htmlspecialchars wrapper 77 * Htmlspecialchars wrapper
78 * Support multidimensional array of strings.
66 * 79 *
67 * @param string $str the string to escape. 80 * @param mixed $input Data to escape: a single string or an array of strings.
68 * 81 *
69 * @return string escaped. 82 * @return string escaped.
70 */ 83 */
71function escape($str) 84function escape($input)
72{ 85{
73 return htmlspecialchars($str, ENT_COMPAT, 'UTF-8', false); 86 if (is_array($input)) {
87 $out = array();
88 foreach($input as $key => $value) {
89 $out[$key] = escape($value);
90 }
91 return $out;
92 }
93 return htmlspecialchars($input, ENT_COMPAT, 'UTF-8', false);
74} 94}
75 95
76/** 96/**
@@ -226,7 +246,7 @@ function space2nbsp($text)
226 * 246 *
227 * @return string formatted description. 247 * @return string formatted description.
228 */ 248 */
229function format_description($description, $redirector) { 249function format_description($description, $redirector = false) {
230 return nl2br(space2nbsp(text2clickable($description, $redirector))); 250 return nl2br(space2nbsp(text2clickable($description, $redirector)));
231} 251}
232 252