Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Dmitry Polushkin http://dmitry.eu/

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Encoding of HTML/XML special chars

   1  
   2  function encode(string) {
   3  	return string.replace('&','&amp;').replace('<','&lt;').replace('>','&gt;').replace('\'','&apos;').replace('"','&quot;');
   4  }

Filename extension

Returns the filename's string extension, else if no extension found returns false.
Example: filename_extension('some_file.mp3'); // mp3
Faster than the pathinfo() analogue in two times.
   1  
   2  function filename_extension($filename) {
   3  	$pos = strrpos($filename, '.');
   4  	if($pos===false) {
   5  		return false;
   6  	} else {
   7  		return substr($filename, $pos+1);
   8  	}
   9  }
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS