Sign up to create your own snipts, or login.

Public snipts » azote's snipts The latest snipts from azote.

showing 1-15 of 15 snipts
  • Parsare immagini da una pagina html
    <?php
      $variabile = "Testo di prova <img src=\"test1.jpg\" alt=\"foto test1\" /><img src=\"test2.jpg\" alt=\"foto test 2\" />";
     
      $documentodom = new DOMDocument;
      $documentodom->loadHTML($variabile);
     
      $xPath = new DOMXPath($documentodom);
     
      $query_path = $xPath->query('//img[@src]');
        foreach ($query_path as $query_path){
        $srcimag = $query_path->getAttribute('src');
        echo "<img src=\"".$srcimag."\" alt=\"Immagini Estratte\" />";
      }
    ?>
    

    copy | embed

    0 comments - tagged in  posted by azote on Dec 03, 2009 at 5:47 a.m. EST
  • CSS font-face embedding
    @font-face {
      font-family: 'Graublau Web';
      src: url('GraublauWeb.eot');
      src: local('Graublau Web Regular'), local('Graublau Web'),
      url('GraublauWeb.otf') format('opentype');
    }
    
    /* From “Bulletproof @font-face syntax” at paulirish.com. */
    

    copy | embed

    0 comments - tagged in  posted by azote on Dec 02, 2009 at 10:30 a.m. EST
  • Get page title from url
    <?php
    function urltitle($url, $window = _blank)
    { // Start Function
        if ($url == null)
        { // Check if the URL is empty
            $url = ""; // Set function output to empty
        }
        else
        { // If not empty carry on
            $http = strpos($url, "http://"); // Check if the url has http:// in it
            if ($http === false)
            { // If not add it
                $url = "http://" . $url; // Add http:// to the url
            }
            $file = @fopen($url, "r"); // Open the url and read it
            if (!$file)
            { // If the url cant be opened
                $url = "<a href="$url" target="$window">$url</a>"; // If it cant be opened function output it the url with the url as the title
            }
            else
            { // If it can be opened carry on
                while (!feof($file))
                { //Tests for end-of-file
                    $line = fgets($file); // Reads file
                    if (preg_match ("@\<title \>(.*)\</title>@i", $line, $out)) {
                    { // Checks for title
                        $url = "<a href="$url" target="$window">$out[1]</a>"; // echo the url with title
                        break;
                    }
                }
            }
            @fclose($file); // Close File
        }
        return $url; // Return function
    }
     
    //ESEMPIO APPLICATO
     
    echo urltitle("http://www.sastgroup.com", "_self"); // URL and Window Type
    echo "". urltitle("http://www.google.com"); // URL and Window Type
    ?>
    

    copy | embed

    0 comments - tagged in  posted by azote on Nov 05, 2009 at 5:47 a.m. EST
  • ASCII image via PHP
    <?php
     
    function image2ascii( $image )
    {
        // return value
        $ret = '';
     
        // open the image
        $img = ImageCreateFromJpeg($image); 
     
        // get width and height
        $width = imagesx($img);
        $height = imagesy($img); 
     
        // loop for height
        for($h=0;$h<$height;$h++)
        {
            // loop for height
            for($w=0;$w<=$width;$w++)
            {
                // add color
                $rgb = ImageColorAt($img, $w, $h);
                $r = ($rgb >> 16) & 0xFF;
                $g = ($rgb >> <img src='http://www.sastgroup.com/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> & 0xFF;
                $b = $rgb & 0xFF;
                // create a hex value from the rgb
                $hex = '#'.str_pad(dechex($r), 2, '0', STR_PAD_LEFT).str_pad(dechex($g), 2, '0', STR_PAD_LEFT).str_pad(dechex($b), 2, '0', STR_PAD_LEFT);
     
                // now add to the return string and we are done
                if($w == $width)
                {
                    $ret .= '';
                }
                else
                {
                    $ret .= '<span style="color:'.$hex.';">#</span>';
                }
            }
        }
        return $ret;
    }
     
    //ESEMPIO APPLICATO
     
    // an image to convert
    $image = 'test.jpg';
     
    // do the conversion
    $ascii = image2ascii( $image );
     
    // and show the world
    echo $ascii; 
     
    ?>
    

    copy | embed

    0 comments - tagged in  posted by azote on Nov 03, 2009 at 4:24 a.m. EST
  • Deny IP
    <?php
    
    $deny = array("111.111.111", "222.222.222", "333.333.333"); //array con indirizzi IP da bloccare
    
    if (in_array ($_SERVER['REMOTE_ADDR'], $deny)) { //controlla se l'indirizzo IP attuale è tra quelli presenti nell'array
    
    header("location: http://www.google.com/"); //se è presente esegue il redirect verso una pagina esterna
    
    exit();
    
    } ?>
    

    copy | embed

    0 comments - tagged in  posted by azote on Jul 21, 2009 at 10:48 a.m. EDT
  • Controllare lo status di un sito
    /* Uso:
    $status = GetServerStatus('http://dominio.com',80)
    o
    $status = GetServerStatus('INDIRIZZOIP',80)
    */
    
    < ?php
    function GetServerStatus($site, $port)
    {
    $status = array("OFFLINE", "ONLINE");
    $fp = @fsockopen($site, $port, $errno, $errstr, 2);
    if (!$fp) {
    return $status[0];
    } else
    { return $status[1];}
    }
    ?>
    

    copy | embed

    0 comments - tagged in  posted by azote on Jul 06, 2009 at 3:27 a.m. EDT
  • Load and parse XML
    var xmlLoader:URLLoader = new URLLoader();
    var xmlData:XML = new XML();
     
    xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
     
    xmlLoader.load(new URLRequest("http://www.kirupa.com/net/files/sampleXML.xml"));
     
    function LoadXML(e:Event):void {
    	xmlData = new XML(e.target.data);
    	trace(xmlData);
    }
    

    copy | embed

    0 comments - tagged in  posted by azote on Jun 26, 2009 at 6:55 a.m. EDT
  • Flash Stage settings
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    
    function resizeHandler(e:Event):void
    {
      mySampleMC.x = (mySampleMC.stage.stageWidth / 2) - (mySampleMC.width / 2);
      mySampleMC.y = (mySampleMC.stage.stageHeight / 2) - (mySampleMC.height / 2);
    }
    
    stage.align = StageAlign.TOP_LEFT;
    stage.scaleMode = StageScaleMode.NO_SCALE;
    stage.addEventListener(Event.RESIZE, resizeHandler);
    
    stage.dispatchEvent(new Event(Event.RESIZE));
    

    copy | embed

    0 comments - tagged in  posted by azote on Jun 26, 2009 at 6:50 a.m. EDT
  • Image loader
    import flash.display.Loader;
    import flash.event.Event;
    import flash.net.URLRequest;
    
    var imageLoader:Loader = new Loader();
    imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event){
     // e.target.content is the newly-loaded image, feel free to addChild it where ever it needs to go...
    });
    imageLoader.load(new URLRequest('yourImage.jpg'));
    

    copy | embed

    0 comments - tagged in  posted by azote on Jun 26, 2009 at 6:25 a.m. EDT
  • Random password generator
    <?php
    
    function create_password($length=8,$use_upper=1,$use_lower=1,$use_number=1,$use_custom=""){
    	$upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    	$lower = "abcdefghijklmnopqrstuvwxyz";
    	$number = "0123456789";
    	if($use_upper){
    		$seed_length += 26;
    		$seed .= $upper;
    	}
    	if($use_lower){
    		$seed_length += 26;
    		$seed .= $lower;
    	}
    	if($use_number){
    		$seed_length += 10;
    		$seed .= $number;
    	}
    	if($use_custom){
    		$seed_length +=strlen($use_custom);
    		$seed .= $use_custom;
    	}
    	for($x=1;$x&lt;=$length;$x++){
    		$password .= $seed{rand(0,$seed_length-1)};
    	}
    	return($password);
    }
     
    //USAGE
     
    echo create_password(); // Returns for example a7YmTwG4
    echo create_password(16); // Returns for example Z77OzzS3DgV3OxxP
    echo create_password(8,0,0); // Returns for example 40714215
    echo create_password(10,1,1,1,";,:.-_()"); // Returns for example or)ZA10kpX
    
    ?>
    

    copy | embed

    0 comments - tagged in  posted by azote on Jun 18, 2009 at 8:18 a.m. EDT
  • XML2Array
    <?php
    // found on http://it.php.net/manual/en/function.xml-parse.php
    
    function xml2array($url, $get_attributes = 1, $priority = 'tag')
    {
        $contents = "";
        if (!function_exists('xml_parser_create'))
        {
            return array ();
        }
        $parser = xml_parser_create('');
        if (!($fp = @ fopen($url, 'rb')))
        {
            return array ();
        }
        while (!feof($fp))
        {
            $contents .= fread($fp, 8192);
        }
        fclose($fp);
        xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8");
        xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
        xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
        xml_parse_into_struct($parser, trim($contents), $xml_values);
        xml_parser_free($parser);
        if (!$xml_values)
            return; //Hmm...
        $xml_array = array ();
        $parents = array ();
        $opened_tags = array ();
        $arr = array ();
        $current = & $xml_array;
        $repeated_tag_index = array ();
        foreach ($xml_values as $data)
        {
            unset ($attributes, $value);
            extract($data);
            $result = array ();
            $attributes_data = array ();
            if (isset ($value))
            {
                if ($priority == 'tag')
                    $result = $value;
                else
                    $result['value'] = $value;
            }
            if (isset ($attributes) and $get_attributes)
            {
                foreach ($attributes as $attr => $val)
                {
                    if ($priority == 'tag')
                        $attributes_data[$attr] = $val;
                    else
                        $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr'
                }
            }
            if ($type == "open")
            {
                $parent[$level -1] = & $current;
                if (!is_array($current) or (!in_array($tag, array_keys($current))))
                {
                    $current[$tag] = $result;
                    if ($attributes_data)
                        $current[$tag . '_attr'] = $attributes_data;
                    $repeated_tag_index[$tag . '_' . $level] = 1;
                    $current = & $current[$tag];
                }
                else
                {
                    if (isset ($current[$tag][0]))
                    {
                        $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
                        $repeated_tag_index[$tag . '_' . $level]++;
                    }
                    else
                    {
                        $current[$tag] = array (
                            $current[$tag],
                            $result
                        );
                        $repeated_tag_index[$tag . '_' . $level] = 2;
                        if (isset ($current[$tag . '_attr']))
                        {
                            $current[$tag]['0_attr'] = $current[$tag . '_attr'];
                            unset ($current[$tag . '_attr']);
                        }
                    }
                    $last_item_index = $repeated_tag_index[$tag . '_' . $level] - 1;
                    $current = & $current[$tag][$last_item_index];
                }
            }
            elseif ($type == "complete")
            {
                if (!isset ($current[$tag]))
                {
                    $current[$tag] = $result;
                    $repeated_tag_index[$tag . '_' . $level] = 1;
                    if ($priority == 'tag' and $attributes_data)
                        $current[$tag . '_attr'] = $attributes_data;
                }
                else
                {
                    if (isset ($current[$tag][0]) and is_array($current[$tag]))
                    {
                        $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
                        if ($priority == 'tag' and $get_attributes and $attributes_data)
                        {
                            $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
                        }
                        $repeated_tag_index[$tag . '_' . $level]++;
                    }
                    else
                    {
                        $current[$tag] = array (
                            $current[$tag],
                            $result
                        );
                        $repeated_tag_index[$tag . '_' . $level] = 1;
                        if ($priority == 'tag' and $get_attributes)
                        {
                            if (isset ($current[$tag . '_attr']))
                            {
                                $current[$tag]['0_attr'] = $current[$tag . '_attr'];
                                unset ($current[$tag . '_attr']);
                            }
                            if ($attributes_data)
                            {
                                $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
                            }
                        }
                        $repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken
                    }
                }
            }
            elseif ($type == 'close')
            {
                $current = & $parent[$level -1];
            }
        }
        return ($xml_array);
    }
    
    $arr = xml2array('http://search.issuu.com/api/1_0/generic?q=user:azote&sort=created&reverse=true&type=document');
    ?>
    

    copy | embed

    0 comments - tagged in  posted by azote on May 26, 2009 at 9:09 a.m. EDT
  • Disable all links with jquery
    <script type="text/javascript">
    $("a").click(function() { return false; });
    </script>
    

    copy | embed

    0 comments - tagged in  posted by azote on May 20, 2009 at 8:05 a.m. EDT
  • Get document height (cross-browser)
    function getDocHeight() {
        var D = document;
        return Math.max(
            Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
            Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
            Math.max(D.body.clientHeight, D.documentElement.clientHeight)
        );
    }
    
    by: http://james.padolsey.com/javascript/get-document-height-cross-browser/http://snipt.net/azote#
    

    copy | embed

    0 comments - tagged in  posted by azote on Jan 27, 2009 at 7:13 a.m. EST
  • Semi-Transparent PNG on IE By Fabrizio Calderan
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="it" xml:lang="it">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
            <title>Test Background PNG24</title>
            
            <style type="text/css">
            body {
                background          : url(immagine-test.jpg) top left no-repeat; 
                color               : #fff;
            }
            
            
            
            .overlay { 
                background-image	: url(bg30.png); 
                width               : 300px;
                height              : 200px;
            }
            </style>
    
            <!--[if lte IE 6]>
                <style type="text/css">
                .overlay {
                    background-image	: url(bg100.gif);
                    filter				: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="bg30.png", sizingMethod="scale");
                }
            </style>
            <![endif]--> 
            
                
            
        </head>
    
    <body>
    
        <div class="overlay">
        Prova testo su sfondo trasparente al 30%
        </div>
    
    </body>
    </html>
    

    copy | embed

    0 comments - tagged in  posted by azote on Jan 16, 2009 at 9:00 a.m. EST
  • PaperBase: Scena base per PaperVision http://papervision2.com/3-creating-a-papervision-base-template/
    /**
    * ...
    * @author Luke Mitchell
    * @version 1.8.0
    */
    
    package  {
    	// These lines make different 'pieces' available in your code.
    	import flash.display.Sprite; // To extend this class
    	import flash.events.Event; // To work out when a frame is entered.
    	import org.papervision3d.core.proto.CameraObject3D;
    	
    	import org.papervision3d.view.Viewport3D; // We need a viewport
    	import org.papervision3d.cameras.*; // Import all types of camera
    	import org.papervision3d.scenes.Scene3D; // We'll need at least one scene
    	import org.papervision3d.render.BasicRenderEngine; // And we need a renderer
    	
    	public class PaperBase extends Sprite { //Must be "extends Sprite"
    		
    		public var viewport:Viewport3D; // The Viewport
    		public var renderer:BasicRenderEngine; // Rendering engine
    		
    		public var current_scene:Scene3D;
    		public var current_camera:CameraObject3D;
    		public var current_viewport:Viewport3D;
    		// -- Scenes -- //
    		public var default_scene:Scene3D; // A Scene
    		// -- Cameras --//
    		public var default_camera:Camera3D; // A Camera
    		
    		public function init(vpWidth:Number = 800, vpHeight:Number = 600):void {
    			initPapervision(vpWidth, vpHeight); // Initialise papervision
    			init3d(); // Initialise the 3d stuff..
    			init2d(); // Initialise the interface..
    			initEvents(); // Set up any event listeners..
    		}
    		
    		protected function initPapervision(vpWidth:Number, vpHeight:Number):void {
    			// Here is where we initialise everything we need to
    			// render a papervision scene.
    			if (vpWidth == 0) {
    				viewport = new Viewport3D(stage.width, stage.height, true, true);
    			}else{
    				viewport = new Viewport3D(vpWidth, vpHeight, false, true);
    			}
    			// The viewport is the object added to the flash scene.
    			// You 'look at' the papervision scene through the viewport
    			// window, which is placed on the flash stage.
    			addChild(viewport); // Add the viewport to the stage.
    			// Initialise the rendering engine.
    			renderer = new BasicRenderEngine();
    			// -- Initialise the Scenes -- //
    			default_scene = new Scene3D();
    			// -- Initialise the Cameras -- //
    			default_camera = new Camera3D();
    			
    			current_camera = default_camera;
    			current_scene = default_scene;
    			current_viewport = viewport;
    			
    		}
    		
    		protected function init3d():void {
    			// This function should hold all of the stages needed
    			// to initialise everything used for papervision.
    			// Models, materials, cameras etc.
    		}
    		
    		protected function init2d():void {
    			// This function should create all of the 2d items
    			// that will be overlayed on your papervision project.
    			// User interfaces, Heads up displays etc.
    		}
    		
    		protected function initEvents():void {
    			// This function makes the onFrame function get called for
    			// every frame.
    			addEventListener(Event.ENTER_FRAME, onEnterFrame);
    			// This line of code makes the onEnterFrame function get
    			// called when every frame is entered.
    		}
    		
    		protected function processFrame():void {
    			// Process any movement or animation here.
    		}
    		
    		protected function onEnterFrame( ThisEvent:Event ):void {
    			//We need to render the scene and update anything here.
    			processFrame();
    			renderer.renderScene(current_scene, current_camera, current_viewport);
    		}
    		
    	}
    	
    }
    

    copy | embed

    0 comments - tagged in  posted by azote on Dec 15, 2008 at 4:50 a.m. EST
Sign up to create your own snipts, or login.