View Source

/hsphere/local/home/c251266/sunsetvines.com/www.sunsetvines.com/sunsetvines/current/vendor/creovel/helpers/text.php (2.119 KB)

#0001  
#0002  
#0003  
#0004  
#0005  
#0006  
#0007  
#0008  
#0009  
#0010  
#0011  
#0012  
#0013  
#0014  
#0015  
#0016  
#0017  
#0018  
#0019  
#0020  
#0021  
#0022  
#0023  
#0024  
#0025  
#0026  
#0027  
#0028  
#0029  
#0030  
#0031  
#0032  
#0033  
#0034  
#0035  
#0036  
#0037  
#0038  
#0039  
#0040  
#0041  
#0042  
#0043  
#0044  
#0045  
#0046  
#0047  
#0048  
#0049  
#0050  
#0051  
#0052  
#0053  
#0054  
#0055  
#0056  
#0057  
#0058  
#0059  
#0060  
#0061  
#0062  
#0063  
#0064  
#0065  
#0066  
#0067  
#0068  
#0069  
#0070  
#0071  
#0072  
#0073  
#0074  
#0075  
#0076  
#0077  
#0078  
#0079  
#0080  
#0081  
#0082  
#0083  
#0084  
#0085  
#0086  
#0087  
#0088  
#0089  
#0090  
#0091  
#0092  
#0093  
#0094  
#0095  
#0096  
#0097  
#0098  
#0099  
#0100  
#0101  
#0102  
#0103  
#0104  
#0105  
#0106  
#0107  
#0108  
#0109  
#0110  
#0111  
#0112  
#0113  
<?php
/**
 * Returns a pluralized verision of a word.
 */
function pluralize($word$count null)
{
    if ( 
$count == ) return $word;
    return 
inflector::pluralize($word);
}

/**
 * Returns a singularized verision of a word.
 */
function singularize($word)
{
    return 
inflector::singularize($word);
}

/**
 * Transform text like 'programmers_field' to 'Programmers Field'
 */
function humanize($word)
{
    return 
inflector::titleize($word);


/*
 * Transform text like 'programmers_field' to 'ProgrammersField'
 */    
function camelize($word)
{
    return 
inflector::camelize($word);
}    

/*
 * Transforms text like 'ProgrammersField' to 'programmers_field'
 */    
function underscore($word)
{
    return 
inflector::underscore($word);
}

/**
 * Helpful for alternating between between two values during a loop.
 *
 * <code>
 *  <tr class="<?=cycle('data_alt1', 'data_alt2')?>">
 *
 *  <tr class="data_alt<?=cycle()?>">
 * </code> 
 *
 * @author Nesbert Hidalgo
 * @return int/string
 */
 
function cycle($var1 null$var2 null)
{
    static 
$return;
    
$var1 $var1 $var1 1;
    
$var2 $var2 $var2 2;
    
$return = ( $return == $var2 || !$return $var1 $var2 );
    return 
$return;
}

/*
 * Replace every " (quote) with its html equevelant
 *
 * @author Nesbert Hidalgo
 * @param string $str required
 * @return string
 */
function quote2string($str)
{
    return 
str_replace("\"""&quot;"$str);
}

/*
 * Replace every charactor of a string with $mask
 *
 * @author Nesbert Hidalgo
 * @param string $str required
 * @param string $mask optional default set to '*'
 * @return string
 */
function mask($str$mask '*')
{
    for ( 
$i 0$i <= ( strlen($str) - ); $i++ ) $return .= $mask;
    return 
$return;
}

/*
 * Truncates a tring and add trailing periods to it
 *
 * @author Nesbert Hidalgo
 * @param string $str required
 * @param string $length optional default set to '*'
 * @param string $tail optional default set to '...'
 * @return string
 */
function truncate($str$length 30$tail '...')
{    
    
$str trim($str);

    if ( 
strlen($str) >= $length ) {
    
        
$str trim(substr_replace($str'', ($length strlen($tail))));
        
$str .= $tail;
    
    }
    
    return 
$str;
}
?>