Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Usefull Snippets

  1. #1
    Member looony's Avatar
    Join Date
    Sep 2008
    Location
    Australia
    Posts
    95
    Thanks
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Default Usefull Snippets

    this came in usefull for me so il thought i would ad it here
    Code:
    <?php
    function shortenurl($url){
        $length = strlen($url);
        if($length > 45){
            $length = $length - 30;
            $first = substr($url, 0, -$length);
            $last = substr($url, -15);
            $newurl = $first."[ ... ]".$last;
            return $newurl;
        }else{
            return $url;
        }
    }
    
    $longurl = "http://www.google.com/search?hl=en&client=firefox-a&channel=s&rls=org.mozilla%3Aen-US%3Aofficial&hs=BCR&q=metacafe&btnG=Search";
    $shorturl = shortenurl($longurl);
    echo"<a href=\"$longurl\">$shorturl</a>";
    ?>
    $longurl is the long url that you want shortened.
    $shorturl is calling the function to shorten the url down to 45 characters.

  2. #2
    Member looony's Avatar
    Join Date
    Sep 2008
    Location
    Australia
    Posts
    95
    Thanks
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Default

    tumbnails script
    Code:
    // this script creates a thumbnail image from an image file - can be a .jpg .gif or .png file 
    // where $thumbsize is the maximum width or height of the resized thumbnail image
    // where this script is named resize.php 
    // call this script with an image tag 
    // [img]resize.php?path=imagepath[/img] where path is a relative path such as subdirectory/image.jpg 
    $thumbsize = 200; 
    $imagesource = $_GET['path']; 
    $filetype = substr($imagesource,strlen($imagesource)-4,4); 
    $filetype = strtolower($filetype); 
    if($filetype == ".gif") $image = @imagecreatefromgif($imagesource); 
    if($filetype == ".jpg") $image = @imagecreatefromjpeg($imagesource); 
    if($filetype == ".png") $image = @imagecreatefrompng($imagesource); 
    if (!$image) die(); 
    $imagewidth = imagesx($image); 
    $imageheight = imagesy($image); 
    if ($imagewidth >= $imageheight) { 
      $thumbwidth = $thumbsize; 
      $factor = $thumbsize / $imagewidth; 
      $thumbheight = $imageheight * $factor; 
    } 
    if ($imageheight >= $imagewidth) { 
      $thumbheight = $thumbsize; 
      $factor = $thumbsize / $imageheight; 
      $thumbwidth = $imagewidth * $factor; 
    } 
    $thumb = @imagecreatetruecolor($thumbwidth,$thumbheight); 
    imagecopyresized($thumb, $image, 0, 0, 0, 0, $thumbwidth, $thumbheight, $imagewidth, $imageheight); 
    imagejpeg($thumb); 
    imagedestroy($image); 
    imagedestroy($thumb);

  3. #3
    Member looony's Avatar
    Join Date
    Sep 2008
    Location
    Australia
    Posts
    95
    Thanks
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Default

    random images script
    Code:
    $array = array(&#39;one&#39;,&#39;two&#39;,&#39;three&#39;,&#39;four&#39;,&#39;five&#39;);
    $count = count($array) - 1;
    $rand = rand (0,$count);
    echo (&#39;[img]&#39;.$array[$rand].&#39;[/img]&#39;);

  4. #4
    Member looony's Avatar
    Join Date
    Sep 2008
    Location
    Australia
    Posts
    95
    Thanks
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Default

    detect language script
    Code:
    <?php
    
    function lixlpixel_get_env_var($Var)
    {
         if(empty($GLOBALS[$Var]))
         {
             $GLOBALS[$Var]=(!empty($GLOBALS['_SERVER'][$Var]))?
             $GLOBALS['_SERVER'][$Var] : (!empty($GLOBALS['HTTP_SERVER_VARS'][$Var])) ? $GLOBALS['HTTP_SERVER_VARS'][$Var]:'';
         }
    }
    
    function lixlpixel_detect_lang()
    {
         // Detect HTTP_ACCEPT_LANGUAGE & HTTP_USER_AGENT.
         lixlpixel_get_env_var('HTTP_ACCEPT_LANGUAGE');
         lixlpixel_get_env_var('HTTP_USER_AGENT');
    
         $_AL=strtolower($GLOBALS['HTTP_ACCEPT_LANGUAGE']);
         $_UA=strtolower($GLOBALS['HTTP_USER_AGENT']);
      
         // Try to detect Primary language if several languages are accepted.
         foreach($GLOBALS['_LANG'] as $K)
         {
             if(strpos($_AL, $K)===0)
             return $K;
         }
      
         // Try to detect any language if not yet detected.
         foreach($GLOBALS['_LANG'] as $K)
         {
             if(strpos($_AL, $K)!==false)
             return $K;
         }
         foreach($GLOBALS['_LANG'] as $K)
         {
             if(preg_match("/[[( ]{$K}[;,_-)]/",$_UA))
             return $K;
         }
    
         // Return default language if language is not yet detected.
         return $GLOBALS['_DLANG'];
    }
    
    // Define default language.
    $GLOBALS['_DLANG']='en';
    
    // Define all available languages.
    // WARNING: uncomment all available languages
    
    $GLOBALS['_LANG'] = array(
    'af', // afrikaans.
    'ar', // arabic.
    'bg', // bulgarian.
    'ca', // catalan.
    'cs', // czech.
    'da', // danish.
    'de', // german.
    'el', // greek.
    'en', // english.
    'es', // spanish.
    'et', // estonian.
    'fi', // finnish.
    'fr', // french.
    'gl', // galician.
    'he', // hebrew.
    'hi', // hindi.
    'hr', // croatian.
    'hu', // hungarian.
    'id', // indonesian.
    'it', // italian.
    'ja', // japanese.
    'ko', // korean.
    'ka', // georgian.
    'lt', // lithuanian.
    'lv', // latvian.
    'ms', // malay.
    'nl', // dutch.
    'no', // norwegian.
    'pl', // polish.
    'pt', // portuguese.
    'ro', // romanian.
    'ru', // russian.
    'sk', // slovak.
    'sl', // slovenian.
    'sq', // albanian.
    'sr', // serbian.
    'sv', // swedish.
    'th', // thai.
    'tr', // turkish.
    'uk', // ukrainian.
    'zh' // chinese.
    );
    
    // Redirect to the correct location.
    
    //header('location: http://www.your_site.com/index_'.lixlpixel_detect_lang().'.php'); // Example Implementation
    echo 'The Language detected is: '.lixlpixel_detect_lang(); // For Demonstration
    
    ?>

  5. The Following User Says Thank You to looony For This Useful Post:

    arnage (02-12-10)

  6. #5
    Member looony's Avatar
    Join Date
    Sep 2008
    Location
    Australia
    Posts
    95
    Thanks
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Default

    generates random password
    Code:
    function generate_passwd($length = 16) {
      static $chars = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ23456789';
      $chars_len = strlen($chars);
      for ($i = 0; $i < $length; $i++)
        $password .= $chars[mt_rand(0, $chars_len - 1)];
      return $password;
    }

  7. #6
    Member
    Join Date
    Jun 2008
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Post

    Mate can u help me !. How did i code if i use your image thumb to resize a ramdom image for example code a random image echo "Random Photo ";
    $panget = mysql_fetch_array(mysql_query("SELECT uid, imageurl FROM ibwf_photo ORDER BY RAND() LIMIT 1"));
    $user = getnick_uid($panget[0]);
    echo "<a href=\"index.php?action=viewmem&amp;pasok=$pasuk&a mp;who=$pic [0]\"/><img src=\"$panget[1]\"/></a>
    ";
    please mate help to resize ..Wml lavalair

  8. #7
    Super Moderator subzero's Avatar
    Join Date
    Mar 2006
    Location
    Your Screen.
    Posts
    3,971
    Thanks
    442
    Thanked 379 Times in 180 Posts
    Blog Entries
    7
    Rep Power
    0

    Default

    image.php
    Code:
    <?php
    
    
    if($_GET['image']){ 
        $image = $_GET['image']; 
    
        if($_GET['type']=="jpg"){ 
            header("Content-type: image/jpeg"); 
        }elseif($_GET['type']=="gif"){ 
            header("Content-type: image/gif"); 
        }elseif($_GET['type']=="png"){ 
            header("Content-type: image/png"); 
        }else{ 
            if(substr($image, -3)=="jpg" || substr($image, -3)=="JPG"){header("Content-type: image/jpeg");} 
            elseif(substr($image, -3)=="gif" || substr($image, -3)=="GIF"){header("Content-type: image/gif");} 
            elseif(substr($image, -3)=="png" || substr($image, -3)=="PNG"){header("Content-type: image/png");} 
        } 
         
        if(substr($image, -3)=="jpg" || substr($image, -3)=="JPG"){$im = imagecreatefromjpeg($image);} 
        elseif(substr($image, -3)=="gif" || substr($image, -3)=="GIF"){$im = imagecreatefromgif($image);} 
        elseif(substr($image, -3)=="png" || substr($image, -3)=="PNG"){$im = imagecreatefrompng($image);} 
         
        if($_GET['percent']){ 
            $x = round((imagesx($im)*$_GET['percent'])/100); 
            $y = round((imagesy($im)*$_GET['percent'])/100); 
            $yyy=0; 
            $xxx=0; 
            $imw = imagecreatetruecolor($x,$y); 
        }elseif($_GET['w'] and $_GET['h']){ 
            $x = $_GET['w']; 
            $y = $_GET['h']; 
            $yyy=0; 
            $xxx=0; 
            $imw = imagecreatetruecolor($x,$y); 
        }elseif($_GET['maxim_size']){ 
            if(imagesy($im)>=$_GET['maxim_size'] || imagesx($im)>=$_GET['maxim_size']){ 
                if(imagesy($im)>=imagesx($im)){ 
                    $y = $_GET['maxim_size']; 
                    $x = ($y*imagesx($im))/imagesy($im); 
                }else{ 
                    $x = $_GET['maxim_size']; 
                    $y = ($x*imagesy($im))/imagesx($im); 
                } 
            }else{ 
                $x = imagesx($im); 
                $y = imagesy($im); 
            } 
            $yyy=0; 
            $xxx=0; 
            $imw = imagecreatetruecolor($x,$y); 
        }elseif($_GET['square']){ 
            if(imagesy($im)>=$_GET['square'] || imagesx($im)>=$_GET['square']){ 
                if(imagesy($im)>=imagesx($im)){ 
                    $x = $_GET['square']; 
                    $y = ($x*imagesy($im))/imagesx($im); 
                    $yyy=-($y-$x)/2; 
                    $xxx=0; 
                }else{ 
                    $y = $_GET['square']; 
                    $x = ($y*imagesx($im))/imagesy($im); 
                    $xxx=-($x-$y)/2; 
                    $yyy=0; 
                } 
            }else{ 
                $x = imagesx($im); 
                $y = imagesy($im); 
                $yyy=0; 
                $xxx=0; 
            } 
            $imw = imagecreatetruecolor($_GET['square'],$_GET['square']); 
        }else{ 
            $x = imagesx($im); 
            $y = imagesy($im); 
            $yyy=0; 
            $xxx=0; 
            $imw = imagecreatetruecolor($x,$y); 
        } 
         
        imagecopyresampled($imw, $im, $xxx,$yyy,0,0,$x,$y,imagesx($im), imagesy($im)); 
         
        if($_GET['watermark_text']){ 
            if($_GET['watermark_color']){$watermark_color=E0E0E0; 
            }else{ 
                $watermark_color="E0E0E0";
            } 
            $red=hexdec(substr($watermark_color,0,2)); 
            $green=hexdec(substr($watermark_color,2,2)); 
            $blue=hexdec(substr($watermark_color,4,2)); 
             
            $text_col = imagecolorallocate($imw, $red,$green,$blue); 
            $font = "georgia.ttf"; //this font(georgia.ttf) heave to be in the same directory as this script 
            $font_size = 12; 
            $angle = 0; 
            $box = imagettfbbox($font_size, $angle, $font, GR.WS); 
            $x = 5; 
            $y = 17; 
            imagettftext($imw, $font_size, $angle, $x, $y, $text_col, $font, GR.WS); 
    
        } 
         
        if($_GET['type']=="jpg"){imagejpeg($imw);} 
        elseif($_GET['type']=="gif"){imagegif($imw);} 
        elseif($_GET['type']=="png"){imagepng($imw);} 
        else{ 
            if(substr($image, -3)=="jpg" || substr($image, -3)=="JPG"){imagejpeg($imw);} 
            elseif(substr($image, -3)=="gif" || substr($image, -3)=="GIF"){imagegif($imw);} 
            elseif(substr($image, -3)=="png" || substr($image, -3)=="PNG"){imagepng($imw);} 
        } 
         
        imagedestroy($imw); 
    } 
    ?>
    $picture = $panget[1];
    echo "<a href=\"index.php?action=viewmem&amp;pasok=$pasuk&a mp;who=$pic [0]\"/><img src=\"image.php?image=".htmlspecialchars($picture) ."&amp;w=100&amp;h=100;\"/></a>
    ";

    This is a safe way to do this
    Visit: [Only registered and activated users can see links. Click Here To Register...]
    Visit: [Only registered and activated users can see links. Click Here To Register...]
    _______
    SCRIPTS FOR SALE BY SUBZERO
    Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders.
    FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others...
    _______
    Info & Tips
    php.net
    w3schools.com

  9. #8
    Member
    Join Date
    Jun 2008
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Post

    wow thanks Master i will try this!!!! Thanks master
    Code:
     $panget = mysql_fetch_array(mysql_query("SELECT uid, imageurl FROM ibwf_gallery ORDER BY RAND() LIMIT 1"));
    $user = getnick_uid($panget[0]);
    $picture = $panget[1];
    echo "<a href=\"index.php?action=viewmem&amp;pasok=$pasok&amp;who=$panget[0]\"/><img src=\"image.php?image=".htmlspecialchars($picture)."&amp;w=100&amp;h=100;\"/></a>
    ";
    master help it does&#39;t show the image i try to use it in xhtml please help me i&#39;m just a noob!!!!

  10. #9
    Super Moderator subzero's Avatar
    Join Date
    Mar 2006
    Location
    Your Screen.
    Posts
    3,971
    Thanks
    442
    Thanked 379 Times in 180 Posts
    Blog Entries
    7
    Rep Power
    0

    Default

    $panget = mysql_fetch_array(mysql_query("SELECT uid, imageurl FROM ibwf_gallery ORDER BY RAND() LIMIT 1"));
    $user = getnick_uid($panget[0]);
    echo "<a href=\"index.php?action=viewmem&amp;pasok=$pasok&a mp;who=$panget[0]\"/><img src=\"image.php?image=$panget[1]&amp;w=100&amp;h=100;\"/></a>
    ";

    Try this
    Visit: [Only registered and activated users can see links. Click Here To Register...]
    Visit: [Only registered and activated users can see links. Click Here To Register...]
    _______
    SCRIPTS FOR SALE BY SUBZERO
    Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders.
    FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others...
    _______
    Info & Tips
    php.net
    w3schools.com

  11. #10
    Member
    Join Date
    Jun 2008
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Post

    thanks Sir,Working Fine Now!!!!!!!!!!!!!!!!

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Little Usefull Code
    By SpiderWap in forum Coding Forum
    Replies: 3
    Last Post: 18-07-08, 21:47
  2. Usefull Script Youownbux Script
    By subzero in forum Scripts Forum
    Replies: 5
    Last Post: 28-05-08, 17:48
  3. Some Usefull Scripts!
    By Death22 in forum Scripts Forum
    Replies: 3
    Last Post: 31-12-07, 20:51
  4. Usefull Wap Scriptt
    By stringfellowhawk in forum Scripts Forum
    Replies: 11
    Last Post: 09-07-07, 20:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

SEO by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19