Created
November 1, 2012 21:06
-
-
Save mrclay/3996542 to your computer and use it in GitHub Desktop.
Generate a string for testing truncation by bytes/characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Generate strings for testing truncation by bytes/characters | |
* | |
* E.g. paste this into a form field: | |
* "€€€€€.... 10....... 20....... 30....... 40....... 50....... 60....... 70....... 80......." | |
* | |
* If this is returned: "€€€€€.... 10....... 20...." you'll know the system is truncating to either | |
* 26 UTF-8 characters or 36 bytes (the five Euros comprise 15 bytes). | |
*/ | |
$minChars = 150; | |
$euro = "\xE2\x82\xAC"; | |
$s = str_repeat($euro, 5) . ".... "; | |
$chars = 10; | |
while ($chars < $minChars) { | |
$s .= (str_pad($chars, 9, '.', STR_PAD_RIGHT) . " "); | |
$chars += 10; | |
} | |
echo $s; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment