With most of the popular web services like Twitter providing their data through APIs, it is always helpful to know how to parse API data which is sent in various formats including JSON, XML etc.
Read More »Latest Posts
Generate An Authentication Code in PHP
This basic snippet will create a random authentication code, or just a random string. <?php # This particular code will generate a random string # that is 25 charicters long 25 comes from the number # that is in the for loop $string = “abcdefghijklmnopqrstuvwxyz0123456789”; for($i=0;$i<25;$i++){ $pos = rand(0,36); $str …
Read More »Encode Email Address using php
With this snippet, you can encode any email address into HTML entities so that spam bots do not find it. function encode_email($email=’info@domain.com’, $linkText=’Contact Us’, $attrs =’class=”emailencoder”‘ ) { // remplazar aroba y puntos $email = str_replace(‘@’, ‘@’, $email); $email = str_replace(‘.’, ‘.’, $email); $email = str_split($email, 5); $linkText = str_replace(‘@’, …
Read More »Passing data from one Activity to another in Android
You can start another activity within the same application by calling startActivity(), passing it an Intent that describes the activity you want to start. Also you can pass some data to the activity “to be started”, using the Intent object too.
Read More »Android Gridview
Android GridView shows items in two-dimensional scrolling grid (rows & columns) and the grid items are not necessarily predetermined but they automatically inserted to the layout using a ListAdapter. An adapter actually bridges between UI components and the data source that fill data into UI Component. Adapter can be used …
Read More »Validate Email Address
Sometimes, while filling forms on your website, a user can mistype his email address. Using the below function you can check if the email provided by user is in correct format.
Read More »SHOW NUMBER OF PEOPLE WHO HAVE LIKED YOUR FACEBOOK PAGE
function fb_fan_count($facebook_name) { $data = json_decode(file_get_contents(“https://graph.facebook.com/”.$facebook_name)); $likes = $data->likes; return $likes; } Syntex: <?php $page = “w2class.com”; $count = fb_fan_count($page); echo $count; ?>
Read More »GET THE SOURCE CODE OF A WEBPAGE
Using the function below you would be able to get the HTML code of any webpage. function display_sourcecode($url) { $lines = file($url); $output = “”; foreach ($lines as $line_num => $line) { // loop thru each line and prepend line numbers $output.= “Line #<b>{$line_num}</b> : ” . htmlspecialchars($line) . “<br>\n”; …
Read More »Android Transparent Background | Set Opacity in Android | Make android application with transparent background
Using this simple code you can make android application background transparent and in other words you can set opacity in background. Step 1 : In your manifest make that activity theme to Translucent- <activity android:name=“com.w2class.transparent.background.MainActivity” android:theme=“@android:style/Theme.Translucent” android:label=“@string/app_name” > Step 2 : Now your page will be 100% transparent, so if you need …
Read More »DETECT LOCATION OF THE USER
Using the below function you can check the city from which the user is visiting your website. function detect_city($ip) { $default = ‘UNKNOWN’; $curlopt_useragent = ‘Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)’; $url = ‘http://ipinfodb.com/ip_locator.php?ip=’ . urlencode($ip); $ch = curl_init(); $curl_opt = array( CURLOPT_FOLLOWLOCATION …
Read More »