Solved – How to Extract Data From XML File PHP

How to Display Value or Extract Data From XML File PHP.

This is very simple way to fetch or extract specific data from a XML file or from a URL by using simplexml_load_file in PHP. I have used this Simple Xml Load File method for many PHP projects.

For example, we are going to use a demo XML file to fetch Specific data by using PHP.

demo.xml file:

Here is the PHP file to Extract Specific Data/Value from above XML file.



AngularJS Tutorial

AngularJS Tutorial for beginners: Learn AngularJS in simple and easy steps starting from zero level. Top AngularJS Interview Questions and Answers for Beginner & Experienced. Top 25 angularjs frequently asked questions. For more: Go to w3schools.

1) What is AngularJS?

Ans) AngularJS is an open-source structural web application framework for dynamic web apps, maintained by Google and a community of individual developers. AngularJS extends HTML attributes with Directives, and binds data to HTML with Expressions. AngularJS is perfect for Single Page Applications (SPAs). AngularJS is a JavaScript framework. It can be added to an HTML page with a <script> tag. It is a library written in JavaScript and distributed as a JavaScript file, and can be added to a web page with a script tag.

2) How to include AngularJS to my webpage?


3) What is ng-app, ng-model and ng-bind ?

Ans) ng-app, ng-model and ng-bind are AngularJS directive.

a) ng-app directive : Used to defines an AngularJS application.
b) ng-model directive : binds the value of HTML controls (input, select, textarea) to application data.
c) ng-bind directive : directive binds application data to the HTML view.


4) What is ng-init in AngularJS?

Ans) ng-init used in AngularJS application to initialize application variables.


5) What is Data Binding in AngularJS?

Ans) Data Binding is used to synchronize AngularJS expressions with AngularJS data. The expression {{ firstName }} is an AngularJS data binding expression.


6) What is ng-repeat in AngularJS?

Ans) ng-repeat in AngularJS is using to repeat HTML Elements.


7) What is AngularJS Expressions?

Ans) AngularJS expressions binds data to HTML, same as ng-bind. AngularJS expressions are written inside double braces: {{ expression }}. AngularJS will "output" data exactly where the expression is written.


Output: My first expression: 10
( Note: If you remove the ng-app directive, then output will be: My first expression: {{ 5 + 5 }} )

8) What is AngularJS Numbers?

Ans) AngularJS numbers are same like JavaScript numbers.


9) What is AngularJS Strings?

Ans) AngularJS Strings are same like JavaScript Strings.


10) What is AngularJS Objects?

Ans) AngularJS objects are same like JavaScript objects.


11) What is AngularJS Arrays?

Ans) AngularJS Arrays are same like JavaScript Arrays.


12) What is AngularJS Controllers?

Ans) AngularJS applications are controlled by controllers. The ng-controller directive defines the controller. The controller code will execute when the page loads.


13) What is Controller Methods in AngularJS?

Ans) Controller Methods in AngularJS is same like functions. A controller can also have methods.


14) What is Filters in AngularJS?

Ans) Filters in AngularJS used to transform data.

Example: uppercase:

15) What is XMLHttpRequest in AngularJS?

XMLHttpRequest: $http is an AngularJS service to read remote server’s data.


16) What is ng-disabled in AngularJS?

Ans) ng-disabled binds AngularJS application data to disabled attribute of HTML elements.


17) What is ng-show in AngularJS?

Ans) ng-show in AngularJS used to show or hide an HTML element.


18) What is ng-hide in AngularJS?

Ans) ng-hide in AngularJS used to hide or show an HTML element.


18) What is ng-click in AngularJS?

Ans) ng-click in AngularJS used to define click event.


19) What is the use of Controller in AngularJS?


Example: Controller Without a Module

Example: Controller With a Module

20) Where to load AngularJS library in webpage?

Ans) You can load AngularJS library in the section or also in body section but always before AngularJS Script.


21) How to include controller and module in AngularJS application?

Ans) Your application should have at least one module file, and one controller file for each controller.

1) Create a module file called “myApp.js”:

2) Create a controller file called “myCtrl.js”:


22) Forms input in AngularJS.


23) How to do form validation in AngularJS?


24) How to use AngularJS with Twitter Bootstrap?


25) How to include another file in AngularJS?

Ans) We can include file by using: ng-include.


Check Directory Exists or Not PHP

How to Check Directory Exists or Not PHP:

If you want to create a file or directory by using PHP Script/Code, first you should have to check whether file or directory/folder exists or not. Sometimes we may need to write a script where we may need to create a file or directory through PHP. But, we cannot simply create a file or directory just like that, we have to check if the file or folder that we are going to create is already exist or not. This is important because any file or folder should not be overwritten. We can use ‘file_exists()’ to check if a file is already present or not. Please note that “file_exists()” function also can be used to check existence of directory. The file_exists() function/method checks whether or not a file or directory exists. This function returns TRUE if the file or directory exists, otherwise it returns FALSE. Syntax: file_exists(path).

PHP Script/Code to Check Directory Exists or Not PHP

Check Directory Exists or Not PHP

The Proper way to check existence of file and directory is only by file_exists function. Read more about “Check Directory Exists or Not PHP” at: PHP.NET.

How to Create a File in PHP:

How to Create Directory/Folder in PHP:

How to Check If Specified File is a Directory/Folder or File:

The “is_dir()” function checks whether the specified file is a directory. This is_dir() function returns TRUE if the directory exists or its directory not file. Syntax: is_dir(file)

Please note that the result of this function “is_dir” is cached, so use clearstatcache() to clear the cache (clearstatcache — Clears file status cache). Also you should have to use clearstatcache() function, if you unlink a file. The function unlink() does not clear the cache if you are performing file_exists() on a remote file:

Force Download File PHP

Find and learn Force Download File PHP:

By default many of file types like: txt, jpg, png, gif, html, pdf, etc. displayed in your web browser instead of download. But you can force browser to download these files instead of showing in browser. In this blog, we will learn how to Force Download File PHP.

PHP Script to Force Download any type of Files:

The above php code will force a specified file to download to user’s/visitor’s computer using the path to the file to download, as well as the output filename.

Above example php script/code for “Force Download File PHP” will output something similar to:

Force Download File PHPNote that readfile() will not present any memory issues, even when you sending large files, on its own. If you get an out of memory error make sure that output buffering is off with ob_get_level(). Find more about readfile method.

If you have very large files, readfile function may cause a large memory usages issue because it stores the whole file to memory and then start download. So you need to read the file as chunks to reduce memory usages.

PHP Script to Force Download any type of very large Files:

Before writing this blog, i seen many download scripts written in PHP, by using many headers and many complex classes, i found at least half of them share common errors. If you want to require a force to download file upon the user visiting a web page with PHP or want to control or track your downloadable contents then above script for “Force Download File PHP” can give you more options.

WordPress Multiple Database

Find and learn about WordPress Multiple Database

Sometime we need to split our main WordPress database to multiple small databases because of large data. Yes, there is a solution in WordPress to transfer some custom tables to other new databases. As you know that wpdb class handlels all database related things like: INSERT, UPDATE, DELETE in WordPress. By default WordPress can only fetch data from a single database in which WordPress is installed. By using $wpdb you can not SELECT, INSERT, UPDATE, DELETE any data from other database, i mean in which WordPress is not installed.

The coding structure of wpdb class is nice and in very simple way that we can easily create many object for different database connection. WordPress created $wpdb object to talk with the database in which WordPress installed, so in the same way, we can also create other object of the same class to do the sql operations in different database.

WordPress Multiple Database

Script for “WordPress Multiple Database”

Please note that if you have two databases with same username and password, then you can fetch record directly like: databasename.tableName

Getting Country City Name from IP Address in PHP

How to Find or Get Country City Name from IP Address in PHP.

In this tutorial you will learn how to Find or Get Country and City Name by IP Address in PHP. First we will have to find the visitor’s/ user’s IP address by using php $_SERVER[‘REMOTE_ADDR’] variable (The IP address from which the user is viewing the current page) then we can easily track our visitor’s location details including City Name, Region Name, Region Code, Continent Code, Region, Country Name, Country Code, Currency Code, Currency Symbol, Currency Symbol UTF8, Currency Converter, Area Code, DMA Code, Latitude, Longitude and also Time Zone by using geoplugin library.

First we will have to find or Get IP Address in PHP, by using $_SERVER[‘REMOTE_ADDR’] variable and then we can fetch Country and City Name from IP Address in PHP:

PHP Script or Code to Get Country and City Name by IP Address in PHP:

Above example PHP script/code for “Country City Name from IP Address in PHP” will output something similar to:

City Name from IP Address in PHP

Find or Detect Timezone by IP Address in PHP

Find more details about “City Name from IP Address in PHP” at Geoplugin.

Show Weather Forecast on Website

Find how to show weather forecast on website in PHP

Looking to add weather information including current temperature, wind, cloudiness, minimum/maximum temperature to your website or blog for local domestic or international city of your choice. You can show weather forecast on website by using some javascript code.

Step 1: Copy below JavaScript code and put it inside your web page’s head tag.

Step 2:Copy and paste below HTML script/code inside your web page’s body tag or anywhre you need to show weather information on website.

Above example script/code to “show weather forecast on website” will output something similar to:

Show Weather Forecast on WebsiteGet more information regarding “show weather forecast on website” at Openweathermap.

Top 5 Weather Widgets to Show Weather Forecast on Website:

1). AccuWeather: AccuWeather provides hourly and Minute forecasts with Superior Accuracy for nearly 3 million locations worldwide, with customized content and engaging video presentations available on smart phones and Internet appliances, as well as via radio, television, and newspapers.

2). WeatherBug: Use WeatherBug weather widgets to display live, local weather conditions, forecasts, severe weather alerts and more on your website, social networking page or blog. Design your very own weather widget or create a weather application using the WeatherBug API.

3). The Weather Channel: The Weather Channel (TWC) has its own widgets for you to use online. First, choose a location by entering in a ZIP code or city and select either standard or metric units. The downside with TWC’s widgets is that there are only two sizes to choose from, so keep that in mind.

4). Weather Forecast Map: Weather Forecast provides plenty of different weather widgets for you to choose from. There are a dozen styles available, ranging from the simple current conditions and forecast to animated eye-catchers.

5). Show My Weather: Show My Weather delivers weather information to you as quickly as possible. No overwrought graphics. No ads all over the website. No fancy but ultimately useless graphics. Keeping it simple.

Get Request or URL Variable in Smarty

How to Get Request or URL Variable in Smarty (Smarty Reserved Variable)

Smarty reserved variable can be used to access request variables such as $_GET, $_POST, $_COOKIE, $_SERVER, $_ENV and $_SESSION.


For more information regarding Smarty reserved variable:

Test Credit Card Numbers

List of Test Credit Card Numbers

Some time we need to use testing credit card information for different types of testing payment process. You can use following credit card numbers to test website’s credit-card purchasing functionality. These credit card numbers validate properly, but are not actually in use. So please use this credit card information only for testing purpose.



Call Static Block in Magento

Find how to call static block in magento:

You can call static blocks in magento in three ways:

1) Call static blocks by using PHP script inside your template file (phtml):

You can also use same script in another way like:

2) Call static blocks by using content field of a CMS page in magento backend:

Go to admin -> CMS -> Pages -> Edit Page -> Content and enter below code. Please don’t forget to change your static block id.

You can also call in another way like:

3) Call static blocks by using Layout Update XML field of a CMS page in magento backend:

Go to admin -> CMS -> Pages -> Edit Page -> Design and enter below code. Please don’t forget to change your static block id.

End of “Find how to call static block in magento”.