Get the time duration from seconds

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 <?php /** * @param integer secs Number of seconds to convert * @return integer Time in weeks, days, hours, minutes, seconds * */ function duration($secs) { $vals = array( 'w' => (int) ($secs / 86400 / 7), 'd' => $secs / 86400 % 7, 'h' => $secs / 3600 % 24, 'm' => $secs / 60 % 60, 's' => $secs % 60 ); $ret = array(); $added = false; foreach ($vals as $key => $timeSC) { if ($timeSC > 0 || $added) { $added = true; $ret[] = $timeSC .
Read more...

Clean multiple new lines in a text

/**
 * Clean duplicates new line
 *
 */
  function cleanNewLine($text)  {
    $newLine = "\r\n";
    $strRes = '';

    $posNewLine = strpos($text, $newLine);
    if ($posNewLine===false) {
      $strRes = $text;

    } else {
      $startText = substr($text, 0, $posNewLine+2);
      $endText = substr($text, $posNewLine+2);
      $strRes .= $startText."";

      // Remove duplicate new line if exists
      $posNewLine = strpos($endText, $newLine);
      while($posNewLine===0) {
        $endText = substr($endText, $posNewLine+2);
        $posNewLine = strpos($endText, $newLine);
      }

      $strRes .= self::cleanNewLine($endText);
    }

    return $strRes;
  }

Split long words in a text

Recursive php function, to split long words:

/**
 * Cut words to max char, in a text
 *
 * @param    string text        Text to check
 * @param    integer maxChar    Max word length
 * @return   string             Verified text
 */
function checkWordLength($text, $maxChar=50) {

    $arrText = explode(' ', $text);
    foreach ($arrText as $key=>$t) {
      if (strlen($t)>$maxChar) {
        $arrText[$key] = chunk_split($t, $maxChar, ' ');
      }
    }

    return implode(' ', $arrText);
}

Use:

$text = checkWordLength($text);

Symfony rollout process with rsync

Symfony has a build-in rsync command line, which makes it easy to rollout your code into production. You can define multiple connections, in case you have multiple servers, a load balancer, backups… In project/config/properties.ini: [symfony] name=codingfolder [production1] host=myapp.example.com port=22 user=myuser dir=/home/myaccount/myproject/ [production2] host=myapp.example.com port=22 user=myuser dir=/home/myaccount/myproject/ Then, from the root directory of your project:
Read more...

About

This is an example of a WordPress page, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many pages like this one or sub-pages as you like and manage all of your content inside of WordPress.