Free SSL Certbot

Certbot, It was Let’s Encrypt Client previously. Automatically enable HTTPS on your website with EFF’s Certbot, deploying Let’s Encrypt certificates.

Server Support

– Apache
– Nginx
– Haproxy
– Plesk

OS Support

– Web Hosting Service
– Debian 7 (wheezy)
– Debian 8 (jessie)
– Debian 9 (stretch)
– Debian testing/unstable
– Debian (other)
– Ubuntu 17.04 (zesty)
– Ubuntu 16.10 (yakkety)
– Ubuntu 16.04 (xenial)
– Ubuntu 14.04 (trusty)
– Ubuntu (other)
– Gentoo
– Arch Linux
– Fedora 24+
– CentOS 6
– RHEL 6
– CentOS/RHEL 7
– FreeBSD
– OpenBSD 5.9
– OpenBSD 6.0+
– OpenBSD (other)
– macOS
– Devuan Jessie 1.0
– Devuan (other)
– Other UNIX
– Non-UNIX

Install on Ubuntu 17.04 (zesty) Apache

$ sudo apt-get update
$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:certbot/certbot
$ sudo apt-get update
$ sudo apt-get install python-certbot-apache

Get Started https://certbot.eff.org/#ubuntutzesty-apache

$ sudo certbot --apache

$ sudo certbot --apache certonly

Automating renewal

$ sudo certbot renew --dry-run

$ sudo crontab -e

30 1 * * * /usr/bin/certbot renew --quiet

It will run renewal command at 1:30 am, every day.

Install Apache, MySQL, PHP 5.6 on Centos 7

Install Apache

# yum update
# yum install httpd
# systemctl start httpd.service

Now Browser your Apache Server http://Server_IP_address/

Enable Apache to start at server boot

# systemctl enable httpd.service

Install Mariadb MySQL

# yum install mariadb-server mariadb
# systemctl start mariadb
# mysql_secure_installation

Enable MySQL to start at server boot

# systemctl enable mariadb.service

Install PHP 5.6

Install EPEL repository

# rpm -Uvh http://vault.centos.org/7.0.1406/extras/x86_64/Packages/epel-release-7-5.noarch.rpm

Note: Make sure you installed “epel-release-7-5.noarch.rpm” else google it for different location …. search on Google “index of” + epel-release-7-5.noarch.rpm

Install remi repository

# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

Note: Make sure you installed “remi-release-7.rpm” else google it for different location

Enable remi

# yum --enablerepo=remi,remi-php56 install php php-common

Install php 5.6 on Centos 7

# yum --enablerepo=remi,remi-php56 install php-cli php-pear php-pdo php-mysql php-mysqlnd php-pgsql php-sqlite php-gd php-mbstring php-mcrypt php-xml php-simplexml php-curl php-zip

# systemctl restart httpd.service
# chown -R apache:apache /var/www/html/

# chmod -R 775 /var/www/

<?php phpinfo(); ?>

http://Server_IP_address/phpinfo.php

Access Skype SQLite Database

I was working for Online Radio Server setup with Icecast and Skype. This Radio Station was using Skype Group Calls with real listeners of station then I have to feed Live Skype Audio to Icecast Radio Server as Input.

Radio Setup Tools Online Radio Schedule with Skype & Icecast

– SAM Broadcaster
– Icecast Server
– Skype account as Radio Station
– Virtual Audio Cable to manage Icecast / Skype Patch

Radio Listeners normally connect to Radio Server Skype from Website. Listeners can send contact request to Skype then Radio Server Manager Schedule some calls based on Radio Schedule. Radio Server Skype Auto Connect new Skype requests

Radio Station with Icecast Skype Features

– Listeners can chat live on Skype
– Selected Listeners can participate in Live Talk

Now I need to show real status of Radio Server Skype on the Radio Station Website??

I know Skype use SQLite to save Database on computer here “C:/Users/[Radio-Server]/AppData/Roaming/Skype/[Radio-Skype]/main.db”

So, I just have query some tables to get REAL Status of Radio Server Skype

– Radio Server Skype is busy in any CALL?
– Radio Server Skype is Free for next CALL?
– Any Live Radio Schedule is running using Skype Calls?

Skype-SQLite

SQLite Tools

DB Browser for SQLite
Skyperious is a Skype database viewer and merger in Python

Skype-SQLite

PHP with SQLite extension to access Skype Database

PHP-PDO-SQLite

PHP-SQLite

<?php
$skype_path = "C:/Users/[Radio-Server]/AppData/Roaming/Skype/[Radio-Skype]/main.db";

// Path for skype main.db file
$db = new SQLite3($skype_path);

$query = "SELECT id, name FROM Calls where is_active='1';";

$stmt = $db->prepare($query);
$results = $stmt->execute();

$call 	= $results->fetchArray();


// Get all Mamabers for current Skype CALL
$query = "SELECT id, identity, guid FROM CallMembers where call_name='".$call['name']."';";

$stmt = $db->prepare($query);
$results = $stmt->execute();

echo "<pre>";

while($data = $results->fetchArray()){

// Print all records in current Skype CALL
print_r($data); 

}

echo "</pre>";

$db->close();

?>

SQLite-CMD

Bottle: Python Web Framework

I really like Bottle: Python Web Framework. Bottle is very simple, fast and powerful Python micro-framework. It is perfect for small web applications and rapid prototyping where you need simple/small API server.

Bottle is a fast, simple and lightweight WSGI micro web-framework for Python.

Installation

Install Bottle with pip install bottle or download the source package at PyPI.

Download and Install

Install the latest stable release (Bottle runs with Python 2.7 and 3.3+.)

#pip install bottle

Or

#easy_install -U bottle

Or

download bottle.py (unstable) into your project directory.

– app.py
– bottle.py

Example: “Hello World” (app.py)

from bottle import route, run

@route(‘/hello/:name’)
def index(name=’World’):
return ‘Hello %s!‘ % name

run(host=’localhost’, port=8080)

Bottle Python

Point your browser to http://localhost:8080/hello/sandeep

Links

https://github.com/bottlepy/bottle
https://raw.githubusercontent.com/bottlepy/bottle/master/bottle.py

Below find simple routing, template, static CDN, Ajax, redirect functions

Test URL for above bottle python code run on port 7800

# python bottle_example.py

http://localhost:7800/
http://localhost:7800/hello
http://localhost:7800/ajax
http://localhost:7800/redirect
http://localhost:7800/404
http://localhost:7800/upload
http://localhost:7800/tpl (“test” is text file on [Web-App-Root])
http://localhost:7800/static/god.jpg (“god.jpg” saved on [Web-App-Root])

Amazon DynamoDB PHP CRUD using aws.phar

DynamoDB is fully managed, fast and low cost NoSQL database service by Amazon. DynamoDB allows you to offload the administrative operations and scale highly distributed database cluster.

The AWS SDK PHP enables you to use Amazon Web Services like Amazon S3, EC2, RDS, CloudFront, Redshift, DynamoDB, Push Notification Service (SNS) and more from your PHP code project.

AWS.PHAR Now Download aws-php-sdk Packaged Phar from http://pear.amazonwebservices.com/get/aws.phar

# wget http://pear.amazonwebservices.com/get/aws.phar

You can also download the packaged phar here http://docs.aws.amazon.com/aws-sdk-php/v3/download/aws.phar

Include the SDK in your PHP project require ‘/path/to/aws.phar’;

Now download simple dynamodb-php-wrapper from here https://github.com/masayuki0812/dynamodb-php-wrapper/blob/master/DynamoDBWrapper.php

<?php

require_once 'aws.phar';
require_once 'DynamoDBWrapper.php'; 

$ddb = new DynamoDBWrapper(array(
    'key'    => 'XXXXXXXXXXXXXXXXXXXXX',
    'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
    'region' => 'us-east-1'
));

createTable

$result = $ddb->createTable(‘Session’, ‘UserId::N’);
// Create a table ‘Session’, which has a hash key ‘UserId’ as NUMBER.

deleteTable

$result = $ddb->deleteTable(‘Session’);

putItem

$item = array(
‘UserId’ => 1,
‘Name’ => ‘Sandeep’,
);
$result = $ddb->put(‘Session’, $item);

updateItem

$key = array(
‘UserId’ => 1,
);
$update = array(
‘Name’ => array(‘PUT’, ‘SVNLabs’)
);
$result = $ddb->update(‘Session’, $key, $update);

deleteItem

$key = array(
‘UserId’ => 1,
);
$result = $ddb->delete(‘Session’, $key);

Query

$keyConditions = array(
‘UserId’ => 1,
);
$result = $ddb->query(‘Session’, $keyConditions);

Scan

$filter = null;

$result = $ddb->scan(‘Session’, $filter, 1000);

Scan with between date filter

$filter = array(
‘userType’ => “member”,
“date” => array(“BETWEEN”, array(“2016/08/01″,”2016/08/17”))
);
$result = $ddb->scan(“Session”, $filter, 1000);

Other Links

https://docs.aws.amazon.com/aws-sdk-php/v3/guide/getting-started/installation.html
https://github.com/masayuki0812/dynamodb-php-wrapper/wiki
https://github.com/svnlabs/aws-dynamodb-php

Top 10 Tutorials for your Drupal Website

Drupal is one of the most popular and powerful content management systems. Creating your website with Drupal will allow you endless options for design and function. Use these 10 Drupal tutorials to easily give your website features and options you may have never thought possible.

1. Tutorial For Site Setup

Every Drupal website owner should begin with a basic site-building tutorial. The first thing to do, after getting Drupal-compatible web hosting, is to review such a tutorial to create your site’s key elements. This site-setup tutorial will walk you through building your website’s administration menu, site editor, pages, menus, and slideshows.

2. Update Drupal Using Minor Updates and Patches

There are a few types of updates you will come across as a Drupal website owner including, minor, major and patch updates. This tutorial will show you how to keep your installation current to avoid bugs and errors, and maintain the latest module compatibility. Patch updates are often aimed at fixing bugs or security issues and may be released at any time. Minor updates fix site functions errors, and are released less often.

3. Autoloading Awesomeness

This tutorial will show you how to take advantage of autoloading in your visitors web browsers. This is helpful when you want to display video or other media without the user having to click ‘Play.’ Use the Auto-loading Awesomeness tutorial to follow in the steps of major media and social companies who know rely on the feature, such as Facebook and Instagram.

4. Preparing Your Site for Drupal 8

The latest release of Drupal, as of 2017, is Drupal 8. This tutorial will help you get prepared for a major update to any outdated Drupal sites. IT discusses manual site audits, security updates and audit modules. While your updated your Drupal and installing Drupal 8, you should check that you have Drupal optimized web hosting, so that you can make the most of your Drupal installation.

5. Installing and Editing Drupal Themes

This tutorial is perhaps among the most important for any Drupal user. It shows you how to install and modify themes for your Drupal site by giving you the basics on how themes work. After reviewing this tutorial, even a beginner will be able to choose and install a Drupal theme that’s right for their site. Those with just a few minutes on their hands can learn how to change colors, module positions and add or remove elements.

6. Drupal SEO Tutorial

If you’re focused on marketing and Search Engine Optimization, then this is the Drupal tutorial for you. It will teach you how to create SEO-friendly posts, tags, and headers. Beginning with a focus on mobile Drupal templates and themes, this handy guide will ensure your site doesn’t get buried in the search results.

7. Drupal Modules Tutorial

This tutorial is invaluable for those who want to begin developing Drupal modules and backend coding. It will show you how to use Object-Oriented PHP to create Drupal modules with function in the backend of your site and interactive features for your website’s frontend. Some PHP knowledge is required for this tutorial. Object-Oriented PHP will keep your Drupal site coding from being redundant, and save you time behind the keyboard.

8. Use Node.js with Drupal

Many web developers are used to node.js and want full javascript integration on their Drupal based website. This tutorial will teach you to seamlessly integrate the popular node.js package with Drupal to use them inherently together. Using Node.js on your Drupal site will allow you to build web applications that are as scalable as you need them to be. This would work great for any new social media site or mobile application.

9. Create a Custom Slideshow

Slideshows have many purposes on websites, including rotating content to keep the site fresh, and ensuring certain content has a front-page standing. This tutorial will show you how to easily create a slideshow on your Drupal site using theme libraries and the Slick module. It involves some simple HTML markup and Java which you can copy and paste or make modifications to. Your finished product will look great on any business website, and will rotate three or more images or embedded media modules at your desired speed.

10. Loop Over Objects

This tutorial is among the more advanced on the list, but should appeal to anyone with even a little coding background. It will show you how to loop over objects using the built-in tag IteratorAggregate. If you’re looking to get started practicing your PHP skills on a live site, this tutorial is a great choice and will provide convenient, functional results.

Drupal can be used for personal websites, business and corporate sites, and even blogs. It’s a diverse CMS that allows countless customizations. By following these tutorials you will gain a better understanding of your Drupal interfaces, and be able to add creative elements to your website.

Activate Free SSL Certificate for Website – Cloudflare

Google will soon shame all websites that are unencrypted also Google count HTTPS for ranking factor. Cloudflare provide Free SSL Certificate in your website DNS system. You just need to edit your DNS records / Name-servers

Cloudflare HTTPS protects website from Security Vulnerabilities and DDoS attacks.

Origin Server (Your Domain) ===== HTTP =====> CloudFlare ===== HTTPS =====> Visitors

Setting up your free Cloudflare Flexible SSL

1. Sign up to Cloudflare.com

2. Enter your domain name and Begin Scan

3. Verify all Your DNS Records for your domain

4. Select Free Cloudflare Plan then follow all steps

5. Change Your Nameservers in your domain control panel

6. Goto Crypto tab then activate free SSL. Choose Flexible Type.
Cloudflare will take approx 24 hours to activate new SSL certificate.

7. Other Cloudflare settings for caching

8. For wordpress websites add Page Rules in CloudFlare

You can use WordPress Plugins

CloudFlare Flexible SSL

Cloudflare

WordPress Force HTTPS

Really Simple SSL

SSL Insecure Content Fixer

OR

1. http://www.svnlabs.in/wp-admin/*
Always Online: On, Cache Level: Bypass

2. http://www.svnlabs.in/wp-login.php*
Always Online: On, Cache Level: Bypass

3. http://svnlabs.in/*
Forwarding URL: (Status Code: 301 – Permanent Redirect, Url: https://www.svnlabs.in/$1)

Free SSL

Importing data from non-wordpress mysql database

You have to create an import php file to get the Questions/Answers from a non-wordpress database and bring them into posts in wordpress.

Question Table

<?php

/// non-wordpress database connection string here

require('./wp-load.php');

$results = mysql_query("SELECT * FROM questions");

while ($row = mysql_fetch_assoc($results)) 
{

    $post_information = array(
	'post_title' => wp_strip_all_tags( $row['question'] ),
	'post_content' => $row['answer'],
	'post_category' =>  array(6,7), // Cat Ids
	'post_date' => date('Y-m-d H:i:s', strtotime( $row['timestamp'] )),
	'post_type' => "post",
	'post_excerpt' => "",
	'post_author' => "admin",
	'post_status' => "publish"
	);
	
	$post_id = wp_insert_post( $post_information );		
	
	$filename = "http://www.domain.com/images/post-image.png";   ////  Post Thumbnail Image
	$wp_filetype = wp_check_filetype(basename($filename), null );
	
	$attachment = array(
	  'post_mime_type' => $wp_filetype['type'],
	  'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
	  'post_content' => '',
	  'post_status' => 'inherit'
	);
	
	$attach_id = wp_insert_attachment( $attachment, $filename, $new_post );
	
	//update_post_meta($post_id,'_thumbnail_id',$attach_id);	
	
	add_post_meta($post_id, '_thumbnail_id', $attach_id, true);

}

?>

Select2Array

It’s easy to convert PHP Array to Select Dropdown Box… you need to loop for all element in array to display as dropdown. But may be you ever think for reverse process. Yes, it’s also easy!

You need to scrape / crawl Select box HTML to get PHP Array back from HTML Select Box. Please read our articles for xpath here

Select2Array

<?php

$s = '<select name="country">
<option value="">Country...</option>
<option value="AF">Afghanistan</option>
<option value="AL">Albania</option>
<option value="DZ">Algeria</option>
<option value="AS">American Samoa</option>
<option value="AD">Andorra</option>
<option value="AG">Angola</option>
<option value="AI">Anguilla</option>
<option value="AG">Antigua &amp; Barbuda</option>
<option value="AR">Argentina</option>
<option value="AA">Armenia</option>
<option value="AW">Aruba</option>
<option value="AU">Australia</option>
<option value="AT">Austria</option>
<option value="AZ">Azerbaijan</option>
<option value="BS">Bahamas</option>
<option value="BH">Bahrain</option>
<option value="BD">Bangladesh</option>
<option value="BB">Barbados</option>
<option value="BY">Belarus</option>
<option value="BE">Belgium</option>
<option value="BZ">Belize</option>
<option value="BJ">Benin</option>
<option value="BM">Bermuda</option>
<option value="BT">Bhutan</option>
<option value="BO">Bolivia</option>
<option value="BL">Bonaire</option>
<option value="BA">Bosnia &amp; Herzegovina</option>
<option value="BW">Botswana</option>
<option value="BR">Brazil</option>
<option value="BC">British Indian Ocean Ter</option>
<option value="BN">Brunei</option>
<option value="BG">Bulgaria</option>
<option value="BF">Burkina Faso</option>
<option value="BI">Burundi</option>
<option value="KH">Cambodia</option>
<option value="CM">Cameroon</option>
<option value="CA">Canada</option>
<option value="IC">Canary Islands</option>
<option value="CV">Cape Verde</option>
<option value="KY">Cayman Islands</option>
<option value="CF">Central African Republic</option>
<option value="TD">Chad</option>
<option value="CD">Channel Islands</option>
<option value="CL">Chile</option>
<option value="CN">China</option>
<option value="CI">Christmas Island</option>
<option value="CS">Cocos Island</option>
<option value="CO">Colombia</option>
<option value="CC">Comoros</option>
<option value="CG">Congo</option>
<option value="CK">Cook Islands</option>
<option value="CR">Costa Rica</option>
<option value="CT">Cote D\'Ivoire</option>
<option value="HR">Croatia</option>
<option value="CU">Cuba</option>
<option value="CB">Curacao</option>
<option value="CY">Cyprus</option>
<option value="CZ">Czech Republic</option>
<option value="DK">Denmark</option>
<option value="DJ">Djibouti</option>
<option value="DM">Dominica</option>
<option value="DO">Dominican Republic</option>
<option value="TM">East Timor</option>
<option value="EC">Ecuador</option>
<option value="EG">Egypt</option>
<option value="SV">El Salvador</option>
<option value="GQ">Equatorial Guinea</option>
<option value="ER">Eritrea</option>
<option value="EE">Estonia</option>
<option value="ET">Ethiopia</option>
<option value="FA">Falkland Islands</option>
<option value="FO">Faroe Islands</option>
<option value="FJ">Fiji</option>
<option value="FI">Finland</option>
<option value="FR">France</option>
<option value="GF">French Guiana</option>
<option value="PF">French Polynesia</option>
<option value="FS">French Southern Ter</option>
<option value="GA">Gabon</option>
<option value="GM">Gambia</option>
<option value="GE">Georgia</option>
<option value="DE">Germany</option>
<option value="GH">Ghana</option>
<option value="GI">Gibraltar</option>
<option value="GB">Great Britain</option>
<option value="GR">Greece</option>
<option value="GL">Greenland</option>
<option value="GD">Grenada</option>
<option value="GP">Guadeloupe</option>
<option value="GU">Guam</option>
<option value="GT">Guatemala</option>
<option value="GN">Guinea</option>
<option value="GY">Guyana</option>
<option value="HT">Haiti</option>
<option value="HW">Hawaii</option>
<option value="HN">Honduras</option>
<option value="HK">Hong Kong</option>
<option value="HU">Hungary</option>
<option value="IS">Iceland</option>
<option value="IN">India</option>
<option value="ID">Indonesia</option>
<option value="IA">Iran</option>
<option value="IQ">Iraq</option>
<option value="IR">Ireland</option>
<option value="IM">Isle of Man</option>
<option value="IL">Israel</option>
<option value="IT">Italy</option>
<option value="JM">Jamaica</option>
<option value="JP">Japan</option>
<option value="JO">Jordan</option>
<option value="KZ">Kazakhstan</option>
<option value="KE">Kenya</option>
<option value="KI">Kiribati</option>
<option value="NK">Korea North</option>
<option value="KS">Korea South</option>
<option value="KW">Kuwait</option>
<option value="KG">Kyrgyzstan</option>
<option value="LA">Laos</option>
<option value="LV">Latvia</option>
<option value="LB">Lebanon</option>
<option value="LS">Lesotho</option>
<option value="LR">Liberia</option>
<option value="LY">Libya</option>
<option value="LI">Liechtenstein</option>
<option value="LT">Lithuania</option>
<option value="LU">Luxembourg</option>
<option value="MO">Macau</option>
<option value="MK">Macedonia</option>
<option value="MG">Madagascar</option>
<option value="MY">Malaysia</option>
<option value="MW">Malawi</option>
<option value="MV">Maldives</option>
<option value="ML">Mali</option>
<option value="MT">Malta</option>
<option value="MH">Marshall Islands</option>
<option value="MQ">Martinique</option>
<option value="MR">Mauritania</option>
<option value="MU">Mauritius</option>
<option value="ME">Mayotte</option>
<option value="MX">Mexico</option>
<option value="MI">Midway Islands</option>
<option value="MD">Moldova</option>
<option value="MC">Monaco</option>
<option value="MN">Mongolia</option>
<option value="MS">Montserrat</option>
<option value="MA">Morocco</option>
<option value="MZ">Mozambique</option>
<option value="MM">Myanmar</option>
<option value="NA">Nambia</option>
<option value="NU">Nauru</option>
<option value="NP">Nepal</option>
<option value="AN">Netherland Antilles</option>
<option value="NL">Netherlands (Holland, Europe)</option>
<option value="NV">Nevis</option>
<option value="NC">New Caledonia</option>
<option value="NZ">New Zealand</option>
<option value="NI">Nicaragua</option>
<option value="NE">Niger</option>
<option value="NG">Nigeria</option>
<option value="NW">Niue</option>
<option value="NF">Norfolk Island</option>
<option value="NO">Norway</option>
<option value="OM">Oman</option>
<option value="PK">Pakistan</option>
<option value="PW">Palau Island</option>
<option value="PS">Palestine</option>
<option value="PA">Panama</option>
<option value="PG">Papua New Guinea</option>
<option value="PY">Paraguay</option>
<option value="PE">Peru</option>
<option value="PH">Philippines</option>
<option value="PO">Pitcairn Island</option>
<option value="PL">Poland</option>
<option value="PT">Portugal</option>
<option value="PR">Puerto Rico</option>
<option value="QA">Qatar</option>
<option value="ME">Republic of Montenegro</option>
<option value="RS">Republic of Serbia</option>
<option value="RE">Reunion</option>
<option value="RO">Romania</option>
<option value="RU">Russia</option>
<option value="RW">Rwanda</option>
<option value="NT">St Barthelemy</option>
<option value="EU">St Eustatius</option>
<option value="HE">St Helena</option>
<option value="KN">St Kitts-Nevis</option>
<option value="LC">St Lucia</option>
<option value="MB">St Maarten</option>
<option value="PM">St Pierre &amp; Miquelon</option>
<option value="VC">St Vincent &amp; Grenadines</option>
<option value="SP">Saipan</option>
<option value="SO">Samoa</option>
<option value="AS">Samoa American</option>
<option value="SM">San Marino</option>
<option value="ST">Sao Tome &amp; Principe</option>
<option value="SA">Saudi Arabia</option>
<option value="SN">Senegal</option>
<option value="RS">Serbia</option>
<option value="SC">Seychelles</option>
<option value="SL">Sierra Leone</option>
<option value="SG">Singapore</option>
<option value="SK">Slovakia</option>
<option value="SI">Slovenia</option>
<option value="SB">Solomon Islands</option>
<option value="OI">Somalia</option>
<option value="ZA">South Africa</option>
<option value="ES">Spain</option>
<option value="LK">Sri Lanka</option>
<option value="SD">Sudan</option>
<option value="SR">Suriname</option>
<option value="SZ">Swaziland</option>
<option value="SE">Sweden</option>
<option value="CH">Switzerland</option>
<option value="SY">Syria</option>
<option value="TA">Tahiti</option>
<option value="TW">Taiwan</option>
<option value="TJ">Tajikistan</option>
<option value="TZ">Tanzania</option>
<option value="TH">Thailand</option>
<option value="TG">Togo</option>
<option value="TK">Tokelau</option>
<option value="TO">Tonga</option>
<option value="TT">Trinidad &amp; Tobago</option>
<option value="TN">Tunisia</option>
<option value="TR">Turkey</option>
<option value="TU">Turkmenistan</option>
<option value="TC">Turks &amp; Caicos Is</option>
<option value="TV">Tuvalu</option>
<option value="UG">Uganda</option>
<option value="UA">Ukraine</option>
<option value="AE">United Arab Emirates</option>
<option value="GB">United Kingdom</option>
<option value="US">United States of America</option>
<option value="UY">Uruguay</option>
<option value="UZ">Uzbekistan</option>
<option value="VU">Vanuatu</option>
<option value="VS">Vatican City State</option>
<option value="VE">Venezuela</option>
<option value="VN">Vietnam</option>
<option value="VB">Virgin Islands (Brit)</option>
<option value="VA">Virgin Islands (USA)</option>
<option value="WK">Wake Island</option>
<option value="WF">Wallis &amp; Futana Is</option>
<option value="YE">Yemen</option>
<option value="ZR">Zaire</option>
<option value="ZM">Zambia</option>
<option value="ZW">Zimbabwe</option>
</select>';
									

$doc = new DOMDocument();
$doc->loadHTML($s);
$xpath = new DOMXPath($doc);

$options = $xpath->query('*/select/option');

//print_r($options);

$values = array();
foreach ($options as $option) {

     $in = $option->getAttribute('value'); 
	 if($in=="") $in = rand(0,2);
	 $values[$in] = $option->textContent;
}

//print_r($values);
echo "$"."z = ".var_export($values, true).";";


?>

You can apply same logic for more HTML elements using xpath...

Download Select2Array.php