Skip to content

Instantly share code, notes, and snippets.

@stajnert
stajnert / slugify.php
Last active October 11, 2015 07:38
Function creates url properly slug from $text
<?php
/**
* Function creates url properly slug from $text
*
* @param string $text
*/
public function slugify($text)
{
// replace non letter or digits by -
$text = preg_replace('#[^\\pL\d]+#u', '-', $text);
@stajnert
stajnert / even_odd.php
Created August 29, 2012 06:31
Even odd tr
<?php foreach ($jobs as $i => $job): ?>
<tr class="<?php echo fmod($i, 2) ? 'even' : 'odd' ?>">
<?php endforeach; ?>
@stajnert
stajnert / File extension.php
Created August 28, 2012 10:14
Get file extension
function getFileExtension($file_name)
{
return substr(strrchr($file_name, '.'), 1);
}
@stajnert
stajnert / sfWidgetFormChoiceFormatter.php
Created August 23, 2012 11:00
sfWidgetFormChoice formatter - every <li> put in new line
/**
* Metoda konfiguruje formularz
*/
public function configure()
{
$this->widgetSchema['cities'] = new sfWidgetFormChoice(array(
'expanded' => true,
'multiple' => true,
'choices' => Doctrine_Core::getTable('hall')->getListNameForOpenHall(),
'renderer_options' => array('formatter' => array($this, 'formatter'))
@stajnert
stajnert / duplicates.sql
Created August 21, 2012 07:08
Get duplicates from mysql
Single records:
SELECT column, COUNT(*) AS c
FROM table
GROUP BY column
HAVING COUNT(c) > 1
All records:
SELECT *
@stajnert
stajnert / Remove \n and \r mysql
Created August 17, 2012 11:19
Remove \n and \r from column
UPDATE table SET column = REPLACE(REPLACE(column, '\r', ''), '\n', '');