Recent Updates RSS Toggle Comment Threads | Keyboard Shortcuts

  • elmisi

    elmisi 10:11 am on March 30, 2010 Permalink | Reply
    Tags: cookie, , quantaltro   

    function isCookieEnabled()
    {
        return (isset($_COOKIE[ini_get('session.name')])
                && strlen($_COOKIE[ini_get('session.name')])>0);
    }
    
     
  • ensaimado

    ensaimado 8:14 pm on March 25, 2010 Permalink | Reply
    Tags:   

    … Because there will be times in which you may want to include the contents of a php file into a variable.

    	function get_include_contents($filename) {
    
    	    if (is_file($filename)) {
    	        ob_start();
    	        include $filename;
    	        $contents = ob_get_contents();
    	        ob_end_clean();
    	        return $contents;
    	    }
    	    return false;
    	}
    

    I have edited my post to answer dave’s comment below.

    By looking at this funciton you may think it’s just a substitute of file_get_contents().
    The difference is that file_get_contents will return literaly the contents of the file, as opposed to get_include_contents that will actually run the code,
    and because we are turning on output buffering, we can get the output of the script and store it in a string. For example if we have the php file ‘example.php’:

    
    	echo 'The gamma laser toxic spill gave me powers';
    

    file_get_contents will produce the following result:

    
    	$string = file_get_contents('example.php');
    
    	echo $string;
    	// will output: echo 'The gamma laser toxic spill gave me powers';
    

    If we use get_include_contents() instead, it will produce the following result:

    
    	$string = get_include_contents('example.php');
    
    	echo $string;
    	// will output: The gamma laser toxic spill gave me powers
    

    If you are still thinking why would I want to do this, I will give you a real life example to ilustrate:

    Lets assume that you have the following email template in a file template.php:

    
    echo  'Dear Mr. ' . $params['name'] . ',';
    echo  'All your ' . $params['item'] . ' are belong to us!';
    

    The function could then be extended to accept some paramaters that the template will need to have on scope:

    	function get_include_contents($filename, $params) {
    
    	    if (is_file($filename)) {
    	        ob_start();
    	        include $filename;
    	        $contents = ob_get_contents();
    	        ob_end_clean();
    	        return $contents;
    	    }
    	    return false;
    	}
    

    After that we can send an email using template.php like this:

    
    	$html_email = get_include_contents(
    							   'example.php'
    							   array(
    								   'name'  =>; 'Satan',
    							           'item'  => 'Snakes'
    								  )
    							);
    
    	mail('someemail@blah.com', 'Subject', $html_email);	
    

    The recipient of the email will have a message in his inbox saying:

    
    Dear Mr. Satan,
    All your snakes are belong to us!
    
     
  • reecoo

    reecoo 6:05 pm on March 25, 2010 Permalink | Reply
    Tags: 18-columns, css, fluidgrid, grid, layout,   

    I’ve already been writing about how much i love fluid layouts in this post so i’ll be quick this time.

    How to tranform the 6/9 fluidgrid system from newgoldleaf into an 18 columns one… ?
    not a big deal,
    but it’s always easier to find something to copy and paste, isn’t it?

    1) download fluidgrid system from newgoldleaf
    2) add these lines of code into fluid.gs.css
    3) enjoy!

    div.eighteen_column.section div.one {width:5%;}
    div.eighteen_column.section div.two {width:10%;}
    div.eighteen_column.section div.three {width:15%;}
    div.eighteen_column.section div.four {width:20%;}
    div.eighteen_column.section div.five {width:25%;}
    div.eighteen_column.section div.six {width:30%;}
    div.eighteen_column.section div.seven {width:35%;}
    div.eighteen_column.section div.eight {width:40%;}
    div.eighteen_column.section div.nine {width:45%;}
    div.eighteen_column.section div.ten {width:50%;}
    div.eighteen_column.section div.eleven {width:55%;}
    div.eighteen_column.section div.twelve {width:60%;}
    div.eighteen_column.section div.thirteen {width:65%;}
    div.eighteen_column.section div.fourteen {width:70%;}
    div.eighteen_column.section div.fifteen {width:75%;}
    div.eighteen_column.section div.sixteen {width:80%;}
    div.eighteen_column.section div.seventeen {width:85%;}
    div.eighteen_column.section div.eighteen {width:90%;}
    
     
  • dave

    dave 2:39 pm on March 25, 2010 Permalink | Reply
    Tags: pear, , proxy   

    Do you need to use PEAR, but you are behind a proxy that requires authentication?
    Use this command to set the correct values:

    pear config-set http_proxy http://username:password@proxyhost:port
     
  • dave

    dave 2:21 pm on March 24, 2010 Permalink | Reply
    Tags: , ,   

    One more way to slugify texts in php, without the need of the iconv() function:

        public static function slugify($text) {
    		$text = trim($text);
    		$text = str_replace(".", "", $text);
    		$text = self::removeAccents($text);
    		// replace non letter or digits by -
    		$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
    		// trim
    		$text = trim($text, '-');
    		// lowercase
    		$text = strtolower($text);
    		// remove unwanted characters
    		$text = preg_replace('~[^-\w]+~', '', $text);
    		return $text;
    
    	}
    
    	public static function removeAccents($text) {
    		$text = htmlentities(utf8_decode($text));
    		$remove = array("&", "acute", "grave", "circ", "tilde", "uml");
    		$text = str_replace($remove, "", $text);
    		return $text;
    	}
    

    Put it inside an Utils class, and use it like

    $slug = Utils::slugify("nothingisclear is awesome");
    
     
  • reecoo

    reecoo 9:55 pm on March 23, 2010 Permalink | Reply
    Tags: , ,   

    I really don’t remember if i’ve written this or took it from someone on the web (if you recognize it, please let me know, or just know that i didn’t want to steal it :) ).

    Anyway today i was into slugs and i surprisingly found a php simple-and-working static method for converting strings into slugs and i felt like sharing it:

    /**
     * PHP "iconv" REQUIRED !!!
     * @param object $string
     * @param object $space [optional]
     * @return
     */
    
    public static function convertStringIntoSlug($string,$space="-") {  
    
    	if (function_exists('iconv')) {
            $string = @iconv('UTF-8', 'ASCII//TRANSLIT', $string);
        }  
    
        $string = strtolower(preg_replace("/[^a-zA-Z0-9 -]/","", $string));
        $string = str_replace(" ", $space, $string);
    
        return $string;
    
    }
    

    here i’ve already wrote about a good jquery alternative (written by Leo Caseiro) for doing this

     
  • reecoo

    reecoo 9:23 pm on March 23, 2010 Permalink | Reply
    Tags: hierarchical, , , menu, ,   

    really good menu (filament group calls it “iPod style”) for showing hierarchical data (i’m using it for showing categories in a backEnd).

    Needs couple of adjustments here and there….
    if you’ve spotted a better one, please, let me know.

     
  • reecoo

    reecoo 8:52 pm on March 23, 2010 Permalink | Reply
    Tags: , , , , stringToSlug   

    a really good link for a jquery plugin to transform strings into slugs….also transforming accents, umlauts, and other special letters in the right way.

    name of the plugin: jquery.stringToSlug.js (written by Leo Caseiro)

     
  • reecoo

    reecoo 8:40 pm on March 23, 2010 Permalink | Reply  

    hello world!

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
esc
cancel