PHP strip_tags, while keeping the inner text

function strip_only($str, $tags) {
    if(!is_array($tags)) {
        $tags = (strpos($str, '>') !== false ? explode('>', str_replace('<', '', $tags)) : array($tags));
        if(end($tags) == '') array_pop($tags);
    }
    foreach($tags as $tag) $str = preg_replace('#</?'.$tag.'[^>]*>#is', '', $str);
    return $str;
}

$str = '<p style="text-align:center">Paragraph</p><strong>Bold</strong><br/><span style="color:red">Red</span><h1>Header</h1>';

echo strip_only($str, array('p', 'h1'));
echo strip_only($str, '<p><h1>');

Credit: Steven (php.net)

Get MySQL’s table sizes

Want to check your database size?

SELECT table_schema "Database",
 sum( data_length + index_length ) / 1024 / 1024 "Size (MB)",
 sum( data_free )/ 1024 / 1024 "Free (MB)"
FROM information_schema.TABLES
GROUP BY table_schema ;

This will work in MySQL 5.0.2 and up. For older versions, use:

SHOW TABLE STATUS

Retrieve custom columns in Symfony

Sometimes while retrieving data, you might not need all the columns, especially on a large database query result set.

Symfony, or actually Propel (1.3) allows you to chose what columns to retrieve, and skip the hydrate process:

// Custom column, on large subset
$c = new Criteria();
$c->clearSelectColumns();
$c->addSelectColumn(TitlePeer::ID);
$c->addSelectColumn(TitlePeer::TITLE);
$resTitleRS = TitlePeer::doSelectStmt($c);
// Loop through result and create custom array
while ($row = $resTitleRS->fetch(PDO::FETCH_ASSOC)) {
  $title_id = $row['ID'];
  $title_name = $row['TITLE'];
  $arrTitleDB[$title_id] = $title_name;
}

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;
  }