Thursday 27 November 2014

To find url given string and replace with anchor tag in php

<?php
$str = "Hi I am using google.com going http://google.com and 
where in https://google.com ahcinkg http://google.co.in else http://google.co";
$ss = "";
$sd = explode(" ",$str);
//print_r($sd);
$c=count($sd)."
"; $i=0; while($c>$i){ $regex = "((https?|ftp)\:\/\/)?"; // SCHEME $regex .= "([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?"; // User and Pass $regex .= "([a-z0-9-.]*)\.([a-z]{2,4})"; // Host or IP $regex .= "(\:[0-9]{2,5})?"; // Port $regex .= "(\/([a-z0-9+\$_-]\.?)+)*\/?"; // Path $regex .= "(\?[a-z+&\$_.-][a-z0-9;:@&%=+\/\$_.-]*)?"; // GET Query $regex .= "(#[a-z_.-][a-z0-9+\$_.-]*)?"; // Anchor // $regexp = '/^[a-zA-Z0-9][a-zA-Z0-9\-\_]+[a-zA-Z0-9]$/'; if (true == preg_match("/^$regex$/", $sd[$i])) { if(!in_array("http", parse_url($sd[$i])) && !in_array("https", parse_url($sd[$i]))) { $s1 ="http://".$sd[$i]; echo $ss ="$sd[$i]  "; }elseif(in_array("http", parse_url($sd[$i])) || in_array("https", parse_url($sd[$i]))) { echo $ss ="$sd[$i]  "; } }else{ echo $sd[$i]."  "; } $i++; } ?>

Thursday 20 November 2014

Save image from ulr using JAVA

package com.cakes;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
public class SaveImageFromUrl {
 public static void main(String[] args) throws Exception {
  String imageUrl = "http://www.avajava.com/images/avajavalogo.jpg";
  String destinationFile = "image.jpg";
  saveImage(imageUrl, destinationFile);
 }
 public static void saveImage(String imageUrl, String destinationFile) throws IOException {
  URL url = new URL(imageUrl);
  InputStream is = url.openStream();
  OutputStream os = new FileOutputStream(destinationFile);
  byte[] b = new byte[2048];
  int length;
  while ((length = is.read(b)) != -1) {
   os.write(b, 0, length);
  }
  is.close();
  os.close();
 }
}

Save image from url using php

<?php
$url = "http://www.technotrigger.com/wp-content/uploads/2014/01/house-in-green-field.jpg";
$content = file_get_contents($url);
file_put_contents('flower.jpg', $content);
?>
<img src="flower.jpg">

Friday 14 November 2014

PHP mail() Function with html content type

<?php
$to = "somebody@example.com, somebodyelse@example.com";
$subject = "HTML email";

$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= 'From: <webmaster@example.com>' . "\r\n";
$headers .= 'Cc: myboss@example.com' . "\r\n";

mail($to,$subject,$message,$headers);
?>

Tuesday 11 November 2014

Motorola DROID Turbo Specification & expecting launch india


Specifications:
    Operating system :
        Android 4.4.4, KitKat®
    System Architecture/Processor:
        Motorola Mobile Computing System, including Qualcomm® Snapdragon™ 805 processor with 2.7 GHz
        quad-core CPU (APQ8084) with 64-bit memory access Adreno 420 @ 600 MHz GPU
        Natural Language Processor Contextual Computing Processor
    Memory (RAM):
        3 GB (LPDDR3 with 64-bit access)
    Storage:
        32 GB (All models)*
        64 GB (Black Ballistic Nylon only)*
    Rear Camera:
        21 MP (5248x3936) in 4:3
        15.5 MP (2952x5248) in 16:9 f/2.0 aperture
        Tap anywhere to capture
        Dual LED flash
        Auto focus
        4X digital zoom
        Slow motion video
        Burst mode
        Auto HDR
        Panorama
        Tap to focus
    Front Camera:
        2 MP, 1080p HD Video
    Dimensions:
        Black Ballistic Nylon
        Height: 143.5 mm (5.65 inches)
        Width: 73.3 mm (2.89 inches)
        Curve: 8.3-11.2 mm (0.33-0.44 inches)
        
        Metallic Red, Metallic Black
        Height: 143.5 mm (5.65 inches)
        Width: 73.3 mm (2.89 inches)
        Curve: 7.8-10.6 mm (0.31-0.42 inches)
    SIM card:
        Nano-SIM
    Weight:
        Black Ballistic Nylon
        176 grams (6.2 ounces)
        
        Metallic Red, Metallic Black
        169 grams (6.0 ounces)
    Display:
        5.2” 1440p Quad HD 2560x1440 AMOLED, 565 ppi
        Corning® Gorilla® Glass 3
    Battery:
        3900 mAh
        Mixed-usage Up to 48 hours**
        Supports Motorola Turbo Charger (included):
            Up to 8 hours of mixed usage battery in 15 minutes of charging***
    Water-resistant:    Yes
    Networks:   CDMA, EVDO Rev A, 4G LTE, GSM/UMTS/HSPA+
    Bands:
        CDMA/EVDO Rev A (850, 1900 MHz)
        LTE Cat 4 (Bands 2, 3, 4, 7, 13)
        Carrier Aggregation (B4+13)
        GSM/GPRS/EDGE (850, 900, 1800, 1900 MHz)
        UMTS/HSPA+ (850, 900, 1900, 2100 MHz)
    Connectivity:
        Micro USB
        3.5 mm headset jack
    Bluetooth® Technology:  Bluetooth version 4.0 LE
    Wi-Fi:  802.11 a/b/g/n/ac (dual-band capable), mobile hotspot
    Speakers:   Mono, front-ported
    Audio Playback: 
        AAC, AAC+, Enhanced AAC+, AMR-NB, AMR-WB, MIDI, MP3, PCM/WAVE, FLAC, OGG/Vorbis
    Video Playback: H.263, H.264 AVC, H.265, MPEG-4 SP, VP8
    Video Capture:  4K at 24fps, 1080p at 30fps, 720p Slow Motion
    NFC:    Yes
    Mobile Payment Services:
        Softcard
        Google wallet
    Location Services:  A-GPS
    Sensors:    
        Accelerometer, Ambient Light, eCompass, Gyroscope, Hall Effect, Infrared, Proximity
    Base Colors:
        Black Ballistic Nylon
        Metallic Black
        Metallic Red

Wednesday 5 November 2014

How to disable Ctrl+V (Paste) , Ctrl+X (Cut) and Ctrl+C (Copy) with jQuery?

<script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
 $(document).ready(function(){
      $('#read').bind("cut copy paste",function(e) {
   e.preventDefault();
   alert(" 'Ctrl+c & Ctrl+x & Ctrl+v has been disabled' ")
      });
   });
});
</script>
<input type="text" id="read" />

How to disable right click in mouse event in jquery?

<script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
 $(document).bind('contextmenu', function (e) {
  e.preventDefault();
  alert('Right Click is not allowed');
 });
});
</script>

Tuesday 4 November 2014

How to lowercase of input field in onkeyup event?

Script Method:
<input type="text" id="ele" onkeyup="this.value=this.value.toLowerCase()" >
CSS Method:
Add style "text-transform:uppercase"
<input type="text" id="ele" style='text-transform:lowercase' >

Monday 3 November 2014

How to uppercase of input field in onkeyup event?

Script Method:
<input type="text" id="ele" onkeyup="this.value=this.value.toUpperCase()" >
CSS Method:
Add style "text-transform:uppercase"
<input type="text" id="ele" style='text-transform:uppercase' >