| 1 |
<?php |
| 2 |
|
| 3 |
namespace Safe; |
| 4 |
|
| 5 |
use Safe\Exceptions\StringsException; |
| 6 |
|
| 7 |
/** |
| 8 |
* convert_uudecode decodes a uuencoded string. |
| 9 |
* |
| 10 |
* @param string $data The uuencoded data. |
| 11 |
* @return string Returns the decoded data as a string. |
| 12 |
* @throws StringsException |
| 13 |
* |
| 14 |
*/ |
| 15 |
function convert_uudecode(string $data): string |
| 16 |
{ |
| 17 |
error_clear_last(); |
| 18 |
$result = \convert_uudecode($data); |
| 19 |
if ($result === false) { |
| 20 |
throw StringsException::createFromPhpError(); |
| 21 |
} |
| 22 |
return $result; |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
/** |
| 27 |
* convert_uuencode encodes a string using the uuencode |
| 28 |
* algorithm. |
| 29 |
* |
| 30 |
* Uuencode translates all strings (including binary data) into printable |
| 31 |
* characters, making them safe for network transmissions. Uuencoded data is |
| 32 |
* about 35% larger than the original. |
| 33 |
* |
| 34 |
* @param string $data The data to be encoded. |
| 35 |
* @return string Returns the uuencoded data. |
| 36 |
* @throws StringsException |
| 37 |
* |
| 38 |
*/ |
| 39 |
function convert_uuencode(string $data): string |
| 40 |
{ |
| 41 |
error_clear_last(); |
| 42 |
$result = \convert_uuencode($data); |
| 43 |
if ($result === false) { |
| 44 |
throw StringsException::createFromPhpError(); |
| 45 |
} |
| 46 |
return $result; |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
/** |
| 51 |
* Decodes a hexadecimally encoded binary string. |
| 52 |
* |
| 53 |
* @param string $data Hexadecimal representation of data. |
| 54 |
* @return string Returns the binary representation of the given data. |
| 55 |
* @throws StringsException |
| 56 |
* |
| 57 |
*/ |
| 58 |
function hex2bin(string $data): string |
| 59 |
{ |
| 60 |
error_clear_last(); |
| 61 |
$result = \hex2bin($data); |
| 62 |
if ($result === false) { |
| 63 |
throw StringsException::createFromPhpError(); |
| 64 |
} |
| 65 |
return $result; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
/** |
| 70 |
* Calculates the MD5 hash of the file specified by the |
| 71 |
* filename parameter using the |
| 72 |
* RSA Data Security, Inc. |
| 73 |
* MD5 Message-Digest Algorithm, and returns that hash. |
| 74 |
* The hash is a 32-character hexadecimal number. |
| 75 |
* |
| 76 |
* @param string $filename The filename |
| 77 |
* @param bool $raw_output When TRUE, returns the digest in raw binary format with a length of |
| 78 |
* 16. |
| 79 |
* @return string Returns a string on success, FALSE otherwise. |
| 80 |
* @throws StringsException |
| 81 |
* |
| 82 |
*/ |
| 83 |
function md5_file(string $filename, bool $raw_output = false): string |
| 84 |
{ |
| 85 |
error_clear_last(); |
| 86 |
$result = \md5_file($filename, $raw_output); |
| 87 |
if ($result === false) { |
| 88 |
throw StringsException::createFromPhpError(); |
| 89 |
} |
| 90 |
return $result; |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
/** |
| 95 |
* Calculates the metaphone key of str. |
| 96 |
* |
| 97 |
* Similar to soundex metaphone creates the same key for |
| 98 |
* similar sounding words. It's more accurate than |
| 99 |
* soundex as it knows the basic rules of English |
| 100 |
* pronunciation. The metaphone generated keys are of variable length. |
| 101 |
* |
| 102 |
* Metaphone was developed by Lawrence Philips |
| 103 |
* <lphilips at verity dot com>. It is described in ["Practical |
| 104 |
* Algorithms for Programmers", Binstock & Rex, Addison Wesley, |
| 105 |
* 1995]. |
| 106 |
* |
| 107 |
* @param string $str The input string. |
| 108 |
* @param int $phonemes This parameter restricts the returned metaphone key to |
| 109 |
* phonemes characters in length. |
| 110 |
* The default value of 0 means no restriction. |
| 111 |
* @return string Returns the metaphone key as a string. |
| 112 |
* @throws StringsException |
| 113 |
* |
| 114 |
*/ |
| 115 |
function metaphone(string $str, int $phonemes = 0): string |
| 116 |
{ |
| 117 |
error_clear_last(); |
| 118 |
$result = \metaphone($str, $phonemes); |
| 119 |
if ($result === false) { |
| 120 |
throw StringsException::createFromPhpError(); |
| 121 |
} |
| 122 |
return $result; |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
/** |
| 127 |
* |
| 128 |
* |
| 129 |
* @param string $filename The filename of the file to hash. |
| 130 |
* @param bool $raw_output When TRUE, returns the digest in raw binary format with a length of |
| 131 |
* 20. |
| 132 |
* @return string Returns a string on success, FALSE otherwise. |
| 133 |
* @throws StringsException |
| 134 |
* |
| 135 |
*/ |
| 136 |
function sha1_file(string $filename, bool $raw_output = false): string |
| 137 |
{ |
| 138 |
error_clear_last(); |
| 139 |
$result = \sha1_file($filename, $raw_output); |
| 140 |
if ($result === false) { |
| 141 |
throw StringsException::createFromPhpError(); |
| 142 |
} |
| 143 |
return $result; |
| 144 |
} |
| 145 |
|
| 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 |
|
| 176 |
/** |
| 177 |
* Returns a string produced according to the formatting string |
| 178 |
* format. |
| 179 |
* |
| 180 |
* @param string $format The format string is composed of zero or more directives: |
| 181 |
* ordinary characters (excluding %) that are |
| 182 |
* copied directly to the result and conversion |
| 183 |
* specifications, each of which results in fetching its |
| 184 |
* own parameter. |
| 185 |
* |
| 186 |
* A conversion specification follows this prototype: |
| 187 |
* %[argnum$][flags][width][.precision]specifier. |
| 188 |
* |
| 189 |
* An integer followed by a dollar sign $, |
| 190 |
* to specify which number argument to treat in the conversion. |
| 191 |
* |
| 192 |
* |
| 193 |
* Flags |
| 194 |
* |
| 195 |
* |
| 196 |
* |
| 197 |
* Flag |
| 198 |
* Description |
| 199 |
* |
| 200 |
* |
| 201 |
* |
| 202 |
* |
| 203 |
* - |
| 204 |
* |
| 205 |
* Left-justify within the given field width; |
| 206 |
* Right justification is the default |
| 207 |
* |
| 208 |
* |
| 209 |
* |
| 210 |
* + |
| 211 |
* |
| 212 |
* Prefix positive numbers with a plus sign |
| 213 |
* +; Default only negative |
| 214 |
* are prefixed with a negative sign. |
| 215 |
* |
| 216 |
* |
| 217 |
* |
| 218 |
* (space) |
| 219 |
* |
| 220 |
* Pads the result with spaces. |
| 221 |
* This is the default. |
| 222 |
* |
| 223 |
* |
| 224 |
* |
| 225 |
* 0 |
| 226 |
* |
| 227 |
* Only left-pads numbers with zeros. |
| 228 |
* With s specifiers this can |
| 229 |
* also right-pad with zeros. |
| 230 |
* |
| 231 |
* |
| 232 |
* |
| 233 |
* '(char) |
| 234 |
* |
| 235 |
* Pads the result with the character (char). |
| 236 |
* |
| 237 |
* |
| 238 |
* |
| 239 |
* |
| 240 |
* |
| 241 |
* |
| 242 |
* An integer that says how many characters (minimum) |
| 243 |
* this conversion should result in. |
| 244 |
* |
| 245 |
* A period . followed by an integer |
| 246 |
* who's meaning depends on the specifier: |
| 247 |
* |
| 248 |
* |
| 249 |
* |
| 250 |
* For e, E, |
| 251 |
* f and F |
| 252 |
* specifiers: this is the number of digits to be printed |
| 253 |
* after the decimal point (by default, this is 6). |
| 254 |
* |
| 255 |
* |
| 256 |
* |
| 257 |
* |
| 258 |
* For g and G |
| 259 |
* specifiers: this is the maximum number of significant |
| 260 |
* digits to be printed. |
| 261 |
* |
| 262 |
* |
| 263 |
* |
| 264 |
* |
| 265 |
* For s specifier: it acts as a cutoff point, |
| 266 |
* setting a maximum character limit to the string. |
| 267 |
* |
| 268 |
* |
| 269 |
* |
| 270 |
* |
| 271 |
* |
| 272 |
* If the period is specified without an explicit value for precision, |
| 273 |
* 0 is assumed. |
| 274 |
* |
| 275 |
* |
| 276 |
* |
| 277 |
* |
| 278 |
* Specifiers |
| 279 |
* |
| 280 |
* |
| 281 |
* |
| 282 |
* Specifier |
| 283 |
* Description |
| 284 |
* |
| 285 |
* |
| 286 |
* |
| 287 |
* |
| 288 |
* % |
| 289 |
* |
| 290 |
* A literal percent character. No argument is required. |
| 291 |
* |
| 292 |
* |
| 293 |
* |
| 294 |
* b |
| 295 |
* |
| 296 |
* The argument is treated as an integer and presented |
| 297 |
* as a binary number. |
| 298 |
* |
| 299 |
* |
| 300 |
* |
| 301 |
* c |
| 302 |
* |
| 303 |
* The argument is treated as an integer and presented |
| 304 |
* as the character with that ASCII. |
| 305 |
* |
| 306 |
* |
| 307 |
* |
| 308 |
* d |
| 309 |
* |
| 310 |
* The argument is treated as an integer and presented |
| 311 |
* as a (signed) decimal number. |
| 312 |
* |
| 313 |
* |
| 314 |
* |
| 315 |
* e |
| 316 |
* |
| 317 |
* The argument is treated as scientific notation (e.g. 1.2e+2). |
| 318 |
* The precision specifier stands for the number of digits after the |
| 319 |
* decimal point since PHP 5.2.1. In earlier versions, it was taken as |
| 320 |
* number of significant digits (one less). |
| 321 |
* |
| 322 |
* |
| 323 |
* |
| 324 |
* E |
| 325 |
* |
| 326 |
* Like the e specifier but uses |
| 327 |
* uppercase letter (e.g. 1.2E+2). |
| 328 |
* |
| 329 |
* |
| 330 |
* |
| 331 |
* f |
| 332 |
* |
| 333 |
* The argument is treated as a float and presented |
| 334 |
* as a floating-point number (locale aware). |
| 335 |
* |
| 336 |
* |
| 337 |
* |
| 338 |
* F |
| 339 |
* |
| 340 |
* The argument is treated as a float and presented |
| 341 |
* as a floating-point number (non-locale aware). |
| 342 |
* Available as of PHP 5.0.3. |
| 343 |
* |
| 344 |
* |
| 345 |
* |
| 346 |
* g |
| 347 |
* |
| 348 |
* |
| 349 |
* General format. |
| 350 |
* |
| 351 |
* |
| 352 |
* Let P equal the precision if nonzero, 6 if the precision is omitted, |
| 353 |
* or 1 if the precision is zero. |
| 354 |
* Then, if a conversion with style E would have an exponent of X: |
| 355 |
* |
| 356 |
* |
| 357 |
* If P > X ≥ −4, the conversion is with style f and precision P − (X + 1). |
| 358 |
* Otherwise, the conversion is with style e and precision P − 1. |
| 359 |
* |
| 360 |
* |
| 361 |
* |
| 362 |
* |
| 363 |
* G |
| 364 |
* |
| 365 |
* Like the g specifier but uses |
| 366 |
* E and f. |
| 367 |
* |
| 368 |
* |
| 369 |
* |
| 370 |
* o |
| 371 |
* |
| 372 |
* The argument is treated as an integer and presented |
| 373 |
* as an octal number. |
| 374 |
* |
| 375 |
* |
| 376 |
* |
| 377 |
* s |
| 378 |
* |
| 379 |
* The argument is treated and presented as a string. |
| 380 |
* |
| 381 |
* |
| 382 |
* |
| 383 |
* u |
| 384 |
* |
| 385 |
* The argument is treated as an integer and presented |
| 386 |
* as an unsigned decimal number. |
| 387 |
* |
| 388 |
* |
| 389 |
* |
| 390 |
* x |
| 391 |
* |
| 392 |
* The argument is treated as an integer and presented |
| 393 |
* as a hexadecimal number (with lowercase letters). |
| 394 |
* |
| 395 |
* |
| 396 |
* |
| 397 |
* X |
| 398 |
* |
| 399 |
* The argument is treated as an integer and presented |
| 400 |
* as a hexadecimal number (with uppercase letters). |
| 401 |
* |
| 402 |
* |
| 403 |
* |
| 404 |
* |
| 405 |
* |
| 406 |
* |
| 407 |
* General format. |
| 408 |
* |
| 409 |
* Let P equal the precision if nonzero, 6 if the precision is omitted, |
| 410 |
* or 1 if the precision is zero. |
| 411 |
* Then, if a conversion with style E would have an exponent of X: |
| 412 |
* |
| 413 |
* If P > X ≥ −4, the conversion is with style f and precision P − (X + 1). |
| 414 |
* Otherwise, the conversion is with style e and precision P − 1. |
| 415 |
* |
| 416 |
* The c type specifier ignores padding and width |
| 417 |
* |
| 418 |
* Attempting to use a combination of the string and width specifiers with character sets that require more than one byte per character may result in unexpected results |
| 419 |
* |
| 420 |
* Variables will be co-erced to a suitable type for the specifier: |
| 421 |
* |
| 422 |
* Type Handling |
| 423 |
* |
| 424 |
* |
| 425 |
* |
| 426 |
* Type |
| 427 |
* Specifiers |
| 428 |
* |
| 429 |
* |
| 430 |
* |
| 431 |
* |
| 432 |
* string |
| 433 |
* s |
| 434 |
* |
| 435 |
* |
| 436 |
* integer |
| 437 |
* |
| 438 |
* d, |
| 439 |
* u, |
| 440 |
* c, |
| 441 |
* o, |
| 442 |
* x, |
| 443 |
* X, |
| 444 |
* b |
| 445 |
* |
| 446 |
* |
| 447 |
* |
| 448 |
* double |
| 449 |
* |
| 450 |
* g, |
| 451 |
* G, |
| 452 |
* e, |
| 453 |
* E, |
| 454 |
* f, |
| 455 |
* F |
| 456 |
* |
| 457 |
* |
| 458 |
* |
| 459 |
* |
| 460 |
* |
| 461 |
* @param mixed $params |
| 462 |
* @return string Returns a string produced according to the formatting string |
| 463 |
* format. |
| 464 |
* @throws StringsException |
| 465 |
* |
| 466 |
*/ |
| 467 |
function sprintf(string $format, ...$params): string |
| 468 |
{ |
| 469 |
error_clear_last(); |
| 470 |
if ($params !== []) { |
| 471 |
$result = \sprintf($format, ...$params); |
| 472 |
} else { |
| 473 |
$result = \sprintf($format); |
| 474 |
} |
| 475 |
if ($result === false) { |
| 476 |
throw StringsException::createFromPhpError(); |
| 477 |
} |
| 478 |
return $result; |
| 479 |
} |
| 480 |
|
| 481 |
|
| 482 |
/** |
| 483 |
* Returns the portion of string specified by the |
| 484 |
* start and length parameters. |
| 485 |
* |
| 486 |
* @param string $string The input string. |
| 487 |
* @param int $start If start is non-negative, the returned string |
| 488 |
* will start at the start'th position in |
| 489 |
* string, counting from zero. For instance, |
| 490 |
* in the string 'abcdef', the character at |
| 491 |
* position 0 is 'a', the |
| 492 |
* character at position 2 is |
| 493 |
* 'c', and so forth. |
| 494 |
* |
| 495 |
* If start is negative, the returned string |
| 496 |
* will start at the start'th character |
| 497 |
* from the end of string. |
| 498 |
* |
| 499 |
* If string is less than |
| 500 |
* start characters long, FALSE will be returned. |
| 501 |
* |
| 502 |
* |
| 503 |
* Using a negative start |
| 504 |
* |
| 505 |
* |
| 506 |
* ]]> |
| 507 |
* |
| 508 |
* |
| 509 |
* @param int|null $length If length is given and is positive, the string |
| 510 |
* returned will contain at most length characters |
| 511 |
* beginning from start (depending on the length of |
| 512 |
* string). |
| 513 |
* |
| 514 |
* If length is given and is negative, then that many |
| 515 |
* characters will be omitted from the end of string |
| 516 |
* (after the start position has been calculated when a |
| 517 |
* start is negative). If |
| 518 |
* start denotes the position of this truncation or |
| 519 |
* beyond, FALSE will be returned. |
| 520 |
* |
| 521 |
* If length is given and is 0, |
| 522 |
* FALSE or NULL, an empty string will be returned. |
| 523 |
* |
| 524 |
* If length is omitted, the substring starting from |
| 525 |
* start until the end of the string will be |
| 526 |
* returned. |
| 527 |
* |
| 528 |
* @return string Returns the extracted part of string;, or |
| 529 |
* an empty string. |
| 530 |
* @throws StringsException |
| 531 |
* |
| 532 |
*/ |
| 533 |
function substr(string $string, int $start, ?int $length = null): string |
| 534 |
{ |
| 535 |
error_clear_last(); |
| 536 |
if ($length !== null) { |
| 537 |
$result = \substr($string, $start, $length); |
| 538 |
} else { |
| 539 |
$result = \substr($string, $start); |
| 540 |
} |
| 541 |
if ($result === false) { |
| 542 |
throw StringsException::createFromPhpError(); |
| 543 |
} |
| 544 |
return $result; |
| 545 |
} |
| 546 |
|
| 547 |
|
| 548 |
/** |
| 549 |
* Operates as sprintf but accepts an array of |
| 550 |
* arguments, rather than a variable number of arguments. |
| 551 |
* |
| 552 |
* @param string $format The format string is composed of zero or more directives: |
| 553 |
* ordinary characters (excluding %) that are |
| 554 |
* copied directly to the result and conversion |
| 555 |
* specifications, each of which results in fetching its |
| 556 |
* own parameter. |
| 557 |
* |
| 558 |
* A conversion specification follows this prototype: |
| 559 |
* %[argnum$][flags][width][.precision]specifier. |
| 560 |
* |
| 561 |
* An integer followed by a dollar sign $, |
| 562 |
* to specify which number argument to treat in the conversion. |
| 563 |
* |
| 564 |
* |
| 565 |
* Flags |
| 566 |
* |
| 567 |
* |
| 568 |
* |
| 569 |
* Flag |
| 570 |
* Description |
| 571 |
* |
| 572 |
* |
| 573 |
* |
| 574 |
* |
| 575 |
* - |
| 576 |
* |
| 577 |
* Left-justify within the given field width; |
| 578 |
* Right justification is the default |
| 579 |
* |
| 580 |
* |
| 581 |
* |
| 582 |
* + |
| 583 |
* |
| 584 |
* Prefix positive numbers with a plus sign |
| 585 |
* +; Default only negative |
| 586 |
* are prefixed with a negative sign. |
| 587 |
* |
| 588 |
* |
| 589 |
* |
| 590 |
* (space) |
| 591 |
* |
| 592 |
* Pads the result with spaces. |
| 593 |
* This is the default. |
| 594 |
* |
| 595 |
* |
| 596 |
* |
| 597 |
* 0 |
| 598 |
* |
| 599 |
* Only left-pads numbers with zeros. |
| 600 |
* With s specifiers this can |
| 601 |
* also right-pad with zeros. |
| 602 |
* |
| 603 |
* |
| 604 |
* |
| 605 |
* '(char) |
| 606 |
* |
| 607 |
* Pads the result with the character (char). |
| 608 |
* |
| 609 |
* |
| 610 |
* |
| 611 |
* |
| 612 |
* |
| 613 |
* |
| 614 |
* An integer that says how many characters (minimum) |
| 615 |
* this conversion should result in. |
| 616 |
* |
| 617 |
* A period . followed by an integer |
| 618 |
* who's meaning depends on the specifier: |
| 619 |
* |
| 620 |
* |
| 621 |
* |
| 622 |
* For e, E, |
| 623 |
* f and F |
| 624 |
* specifiers: this is the number of digits to be printed |
| 625 |
* after the decimal point (by default, this is 6). |
| 626 |
* |
| 627 |
* |
| 628 |
* |
| 629 |
* |
| 630 |
* For g and G |
| 631 |
* specifiers: this is the maximum number of significant |
| 632 |
* digits to be printed. |
| 633 |
* |
| 634 |
* |
| 635 |
* |
| 636 |
* |
| 637 |
* For s specifier: it acts as a cutoff point, |
| 638 |
* setting a maximum character limit to the string. |
| 639 |
* |
| 640 |
* |
| 641 |
* |
| 642 |
* |
| 643 |
* |
| 644 |
* If the period is specified without an explicit value for precision, |
| 645 |
* 0 is assumed. |
| 646 |
* |
| 647 |
* |
| 648 |
* |
| 649 |
* |
| 650 |
* Specifiers |
| 651 |
* |
| 652 |
* |
| 653 |
* |
| 654 |
* Specifier |
| 655 |
* Description |
| 656 |
* |
| 657 |
* |
| 658 |
* |
| 659 |
* |
| 660 |
* % |
| 661 |
* |
| 662 |
* A literal percent character. No argument is required. |
| 663 |
* |
| 664 |
* |
| 665 |
* |
| 666 |
* b |
| 667 |
* |
| 668 |
* The argument is treated as an integer and presented |
| 669 |
* as a binary number. |
| 670 |
* |
| 671 |
* |
| 672 |
* |
| 673 |
* c |
| 674 |
* |
| 675 |
* The argument is treated as an integer and presented |
| 676 |
* as the character with that ASCII. |
| 677 |
* |
| 678 |
* |
| 679 |
* |
| 680 |
* d |
| 681 |
* |
| 682 |
* The argument is treated as an integer and presented |
| 683 |
* as a (signed) decimal number. |
| 684 |
* |
| 685 |
* |
| 686 |
* |
| 687 |
* e |
| 688 |
* |
| 689 |
* The argument is treated as scientific notation (e.g. 1.2e+2). |
| 690 |
* The precision specifier stands for the number of digits after the |
| 691 |
* decimal point since PHP 5.2.1. In earlier versions, it was taken as |
| 692 |
* number of significant digits (one less). |
| 693 |
* |
| 694 |
* |
| 695 |
* |
| 696 |
* E |
| 697 |
* |
| 698 |
* Like the e specifier but uses |
| 699 |
* uppercase letter (e.g. 1.2E+2). |
| 700 |
* |
| 701 |
* |
| 702 |
* |
| 703 |
* f |
| 704 |
* |
| 705 |
* The argument is treated as a float and presented |
| 706 |
* as a floating-point number (locale aware). |
| 707 |
* |
| 708 |
* |
| 709 |
* |
| 710 |
* F |
| 711 |
* |
| 712 |
* The argument is treated as a float and presented |
| 713 |
* as a floating-point number (non-locale aware). |
| 714 |
* Available as of PHP 5.0.3. |
| 715 |
* |
| 716 |
* |
| 717 |
* |
| 718 |
* g |
| 719 |
* |
| 720 |
* |
| 721 |
* General format. |
| 722 |
* |
| 723 |
* |
| 724 |
* Let P equal the precision if nonzero, 6 if the precision is omitted, |
| 725 |
* or 1 if the precision is zero. |
| 726 |
* Then, if a conversion with style E would have an exponent of X: |
| 727 |
* |
| 728 |
* |
| 729 |
* If P > X ≥ −4, the conversion is with style f and precision P − (X + 1). |
| 730 |
* Otherwise, the conversion is with style e and precision P − 1. |
| 731 |
* |
| 732 |
* |
| 733 |
* |
| 734 |
* |
| 735 |
* G |
| 736 |
* |
| 737 |
* Like the g specifier but uses |
| 738 |
* E and f. |
| 739 |
* |
| 740 |
* |
| 741 |
* |
| 742 |
* o |
| 743 |
* |
| 744 |
* The argument is treated as an integer and presented |
| 745 |
* as an octal number. |
| 746 |
* |
| 747 |
* |
| 748 |
* |
| 749 |
* s |
| 750 |
* |
| 751 |
* The argument is treated and presented as a string. |
| 752 |
* |
| 753 |
* |
| 754 |
* |
| 755 |
* u |
| 756 |
* |
| 757 |
* The argument is treated as an integer and presented |
| 758 |
* as an unsigned decimal number. |
| 759 |
* |
| 760 |
* |
| 761 |
* |
| 762 |
* x |
| 763 |
* |
| 764 |
* The argument is treated as an integer and presented |
| 765 |
* as a hexadecimal number (with lowercase letters). |
| 766 |
* |
| 767 |
* |
| 768 |
* |
| 769 |
* X |
| 770 |
* |
| 771 |
* The argument is treated as an integer and presented |
| 772 |
* as a hexadecimal number (with uppercase letters). |
| 773 |
* |
| 774 |
* |
| 775 |
* |
| 776 |
* |
| 777 |
* |
| 778 |
* |
| 779 |
* General format. |
| 780 |
* |
| 781 |
* Let P equal the precision if nonzero, 6 if the precision is omitted, |
| 782 |
* or 1 if the precision is zero. |
| 783 |
* Then, if a conversion with style E would have an exponent of X: |
| 784 |
* |
| 785 |
* If P > X ≥ −4, the conversion is with style f and precision P − (X + 1). |
| 786 |
* Otherwise, the conversion is with style e and precision P − 1. |
| 787 |
* |
| 788 |
* The c type specifier ignores padding and width |
| 789 |
* |
| 790 |
* Attempting to use a combination of the string and width specifiers with character sets that require more than one byte per character may result in unexpected results |
| 791 |
* |
| 792 |
* Variables will be co-erced to a suitable type for the specifier: |
| 793 |
* |
| 794 |
* Type Handling |
| 795 |
* |
| 796 |
* |
| 797 |
* |
| 798 |
* Type |
| 799 |
* Specifiers |
| 800 |
* |
| 801 |
* |
| 802 |
* |
| 803 |
* |
| 804 |
* string |
| 805 |
* s |
| 806 |
* |
| 807 |
* |
| 808 |
* integer |
| 809 |
* |
| 810 |
* d, |
| 811 |
* u, |
| 812 |
* c, |
| 813 |
* o, |
| 814 |
* x, |
| 815 |
* X, |
| 816 |
* b |
| 817 |
* |
| 818 |
* |
| 819 |
* |
| 820 |
* double |
| 821 |
* |
| 822 |
* g, |
| 823 |
* G, |
| 824 |
* e, |
| 825 |
* E, |
| 826 |
* f, |
| 827 |
* F |
| 828 |
* |
| 829 |
* |
| 830 |
* |
| 831 |
* |
| 832 |
* |
| 833 |
* @param array $args |
| 834 |
* @return string Return array values as a formatted string according to |
| 835 |
* format. |
| 836 |
* @throws StringsException |
| 837 |
* |
| 838 |
*/ |
| 839 |
function vsprintf(string $format, array $args): string |
| 840 |
{ |
| 841 |
error_clear_last(); |
| 842 |
$result = \vsprintf($format, $args); |
| 843 |
if ($result === false) { |
| 844 |
throw StringsException::createFromPhpError(); |
| 845 |
} |
| 846 |
return $result; |
| 847 |
} |
| 848 |
|