/**
* Cut string to n symbols and add delim but do not break words.
*
* Example:
*
* $string = 'this sentence is way too long';
* echo neat_trim($string, 16);
*
*
* Output: 'this sentence is…'
*
* @access public
* @param string string we are operating with
* @param integer character count to cut to
* @param string|NULL delimiter. Default: '…'
* @return string processed string
**/
function neat_trim($string, $n) {
if (strlen($string) <= $n) {
$string = $string; //do nothing
}
else {
$string = wordwrap($string,$n);
$string = substr($string, 0, strpos($string, "\n"))."...";
}
return $string;
/*$len = strlen($str);
if ($len > $n) {
preg_match('/(.{' . $n . '}.*?)\b/', $str, $matches);
if(isset($matches[1])) {
return rtrim($matches[1]) . $delim;
}
}
else {
return $str;
}*/
}
function ascii_to_entities($str)
{
$count = 1;
$out = '';
$temp = array();
for ($i = 0, $s = strlen($str); $i < $s; $i++)
{
$ordinal = ord($str[$i]);
$out .= ''.$ordinal.';';
}
return $out;
}
// -----------------------------------------------------------------
$mois[1] = "Janvier";
$mois[2] = "Février";
$mois[3] = "Mars";
$mois[4] = "Avril";
$mois[5] = "Mai";
$mois[6] = "Juin";
$mois[7] = "Juillet";
$mois[8] = "Août";
$mois[9] = "Septembre";
$mois[10] = "Octobre";
$mois[11] = "Novembre";
$mois[12] = "Décembre";
$month[1] = "January";
$month[2] = "February";
$month[3] = "March";
$month[4] = "April";
$month[5] = "May";
$month[6] = "June";
$month[7] = "July";
$month[8] = "August";
$month[9] = "September";
$month[10] = "October";
$month[11] = "November";
$month[12] = "December";
function str_rand($length = 16, $seeds = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')
{
$str = '';
$seeds_count = strlen($seeds);
// Seed
list($usec, $sec) = explode(' ', microtime());
$seed = (float) $sec + ((float) $usec * 100000);
mt_srand($seed);
// Generate
for ($i = 0; $length > $i; $i++) {
$str .= $seeds{mt_rand(0, $seeds_count - 1)};
}
return $str;
}
function dump_var($varia) {
echo "
\n"; print_r($varia); echo "\n"; } function toggle_valide($oldval) { if ($oldval == "N") { return 'O'; } else { return 'N'; } } function rt2br($val) { $val = str_replace('> ', "