Skip to content

Instantly share code, notes, and snippets.

@mrclay
Created November 1, 2012 21:06
Show Gist options
  • Save mrclay/3996542 to your computer and use it in GitHub Desktop.
Save mrclay/3996542 to your computer and use it in GitHub Desktop.
Generate a string for testing truncation by bytes/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