@@ -144,6 +144,35 @@ function sha1_file(string $filename, bool $raw_output = false): string
144
144
}
145
145
146
146
147
+ /**
148
+ * Calculates the soundex key of str.
149
+ *
150
+ * Soundex keys have the property that words pronounced similarly
151
+ * produce the same soundex key, and can thus be used to simplify
152
+ * searches in databases where you know the pronunciation but not
153
+ * the spelling. This soundex function returns a string 4 characters
154
+ * long, starting with a letter.
155
+ *
156
+ * This particular soundex function is one described by Donald Knuth
157
+ * in "The Art Of Computer Programming, vol. 3: Sorting And
158
+ * Searching", Addison-Wesley (1973), pp. 391-392.
159
+ *
160
+ * @param string $str The input string.
161
+ * @return string Returns the soundex key as a string.
162
+ * @throws StringsException
163
+ *
164
+ */
165
+ function soundex (string $ str ): string
166
+ {
167
+ error_clear_last ();
168
+ $ result = \soundex ($ str );
169
+ if ($ result === false ) {
170
+ throw StringsException::createFromPhpError ();
171
+ }
172
+ return $ result ;
173
+ }
174
+
175
+
147
176
/**
148
177
* Returns a string produced according to the formatting string
149
178
* format.
@@ -451,7 +480,7 @@ function sprintf(string $format, ...$params): string
451
480
* Returns the portion of string specified by the
452
481
* start and length parameters.
453
482
*
454
- * @param string $string The input string. Must be one character or longer.
483
+ * @param string $string The input string.
455
484
* @param int $start If start is non-negative, the returned string
456
485
* will start at the start'th position in
457
486
* string, counting from zero. For instance,
0 commit comments