Pages

Thursday, 20 March 2014

Read and write from xml file by php

By php it is easy to read from an xml file by php.
The following code is how to read from a xml file:

$doc = new DOMDocument();
$doc->load( 'sample.xml' ); // the file you want to read
 $i = 0;
 
// xml read code
 
  $transaction_ids = $doc->getElementsByTagName( "transaction" );
 
 
  $transactions = $doc->getElementsByTagName( "merchant" );
  $transactions_arr = array();
  foreach( $transactions as $transaction )
    {
      $ids = $transaction->getElementsByTagName( "id" );
      $id = $ids->item(0)->nodeValue;
 
      $names= $transaction->getElementsByTagName( "name" );
      $name= $names->item(0)->nodeValue;
 
      $total_amounts = $transaction->getElementsByTagName( "totalAmount" );
      $total_amount = $total_amounts->item(0)->nodeValue;
     
      $account_names = $transaction->getElementsByTagName( "accountName" );
      $account_name = $account_names->item(0)->nodeValue;
     
      $account_numbers = $transaction->getElementsByTagName( "accountNumber" );
      $account_number = $account_numbers->item(0)->nodeValue;
     
      $transaction_dates = $transaction->getElementsByTagName( "transactionDate" );
      $transaction_date = $transaction_dates->item(0)->nodeValue;
     
      $descriptions = $transaction->getElementsByTagName( "description" );
      $description = $descriptions->item(0)->nodeValue;
     
     
      $transaction_id_arr[$i] = $transaction_ids->item($i)->getAttribute('id');
     
      $transactions_arr[$i]=array('id'=>$id,'name'=>$name,'totalAmount',$total_amount,'accountName'=>$account_name,'accountNumber'=>$account_number,'transactionDate'=>$transaction_date,'description'=>$description);
      $i++;
   
  }

 // xml write code
 
  $doc = new DOMDocument();
  $doc->formatOutput = true;
 
  $c = $doc->createElement( "catalog" );
  $doc->appendChild( $c );
 
  $fname = $doc->createElement( "name" );
  $fname->appendChild( $doc->createTextNode( 'Transaction logs' ) );
  $c->appendChild( $fname );
 
  $creationDate = $doc->createElement( "creationDate" );
  $creationDate->appendChild( $doc->createTextNode( date('Y-m-d') ) );
  $c->appendChild( $fname );
 
  $copyright = $doc->createElement( "copyright" );
  $copyright->appendChild( $doc->createTextNode( 'Copyright (C) clickshopdk.com, All rights reserved.' ) );
  $c->appendChild( $copyright );
 
  $version = $doc->createElement( "version" );
  $version->appendChild( $doc->createTextNode( '1.0' ) );
  $c->appendChild( $version );
 
  $description = $doc->createElement( "description" );
  $description->appendChild( $doc->createTextNode( 'Today transactions details.' ) );
  $c->appendChild( $description );
 

  $j = 0;
 
  foreach( $transactions_arr as $transaction )
  {
      
      $t = $doc->createElement( "transaction" );
        $t->setAttribute('id', $transaction_id_arr[$j]);
        $c->appendChild( $t );
     
      $m = $doc->createElement( "merchant" );
      $t->appendChild( $m );
     
      $id = $doc->createElement( "id" );
      $id->appendChild( $doc->createTextNode( $transaction['id'] ) );
      $m->appendChild( $id );
 
      $name = $doc->createElement( "name" );
      $name->appendChild( $doc->createTextNode( $transaction['name'] ) );
      $m->appendChild( $name );
     
      $totalAmount = $doc->createElement( "totalAmount" );
      $totalAmount->appendChild( $doc->createTextNode( $transaction['totalAmount'] ) );
      $m->appendChild( $totalAmount );
     
      $accountName = $doc->createElement( "accountName" );
      $accountName->appendChild( $doc->createTextNode( $transaction['accountName'] ) );
      $m->appendChild( $accountName );
     
      $accountNumber = $doc->createElement( "accountNumber" );
      $accountNumber->appendChild( $doc->createTextNode( $transaction['accountNumber'] ) );
      $m->appendChild( $accountNumber );
     
      $transactionDate = $doc->createElement( "transactionDate" );
      $transactionDate->appendChild( $doc->createTextNode( $transaction['transactionDate'] ) );
      $m->appendChild( $transactionDate );
     
      $description = $doc->createElement( "description" );
      $description->appendChild( $doc->createTextNode( $transaction['description'] ) );
      $m->appendChild( $description );
 
     
      $j++;
     
  }


//echo $doc->saveXML();
  $doc->save("output.xml");


 you will get the same output xml like sample xml file, because you are reading from sample.xml file.

the sample.xml file is here. download sample.xml




Wednesday, 19 March 2014

an error occurred while processing this directive

In WordPress website or any other site you may get like the following error when you open the site:

 [an error occurred while processing this directive]

This may be happen for your root folder directory permission

Root folder directory permission needs to be 755

If the folder permission is 777 it may cause this error.

I have solved one of my problem by changing the folder perssion from 777 to 755.



Tuesday, 10 December 2013

How to integrate paypal by php

Paypal is the most used online payment gateway in the world. It is secured for both buyer and seller. So, for online transaction both buyers and sellers like to use it. But how PayPal gateway is integrated in web? A lot of tutorials are available in online. I will discuss here about the easiest way to integrate.

I will use PHP language for integrate it.

First Step: Create a Form

Keep the information of product items that you want to sell in a form. It is just a html form tag (<form>). Below is an example of a form:

<form action="https://www.paypal.com/cgi-bin/webscr" method="POST">

<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="business" value="nurulsnit@gmail.com">
<input type="hidden" name="item_name" id="item_name" value="My Product" />           
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="amount" value="10" />

<input type="submit" value="Buy Now"  />

</form>

Explanation of the above code:
Form action = https://www.paypal.com/cgi-bin/webscr. It is live paypal link. If you want to test the payment you can use sandbox paypal link. ( Sandbox is a test mode of paypal, in next post i will discuss about sandbox ).

Sandbox form action will be = https://www.sandbox.paypal.com/cgi-bin/webscr

<input type="hidden" name="cmd" value="_xclick" />, it is an essential variable for paypal transaction. This is a hidden type variable which name is cmd and value = _xclick.

business variable contains your paypal business account mail address. In this paypal account the payment will send. It is the seller paypal id.
item_name is the product name which is selling or purchasing.
currency_code is the currency name of transaction.
amount is the product price amount.
        

Monday, 25 November 2013

Date format change by php code

For software development we need different types of date format.

We can do it by a simple line of code. There is an example below:
$cdate = '2013-10-25';  // Y-m-d format
$rdate = date("d-m-Y",strtotime($cdate));  // d-m-Y format
echo $rdate;
I think it will help you.

Tuesday, 12 November 2013

Take difinite number of word from a string

The following function is for to take a definite number of words from an string:

function take_definite_number_word( $words = 10)
{
     $wordCount = count(explode("",$item->description));      // count by space
     if ($wordCount<$words)
    {
            $adjustedText = $item->description;
     }
     else
    {
          $adjustedText = implode(" ", array_slice(explode(" ",$item->description), 0, $words));
    }
}

Sunday, 29 September 2013

youtube video is not showing in Mozilla Firefox but google chorome and safary ok

It is a recent problem/bug with Mozilla Firefox browser.
We know, in your computer the browser is updating each time if you are net connected.
If you open your Mozilla Firefox browser and click on Help->About Firefox the it search the latest version of Firefox and update it.

In latest version of Mozilla Firefox it is now showing embeded  videos like youtube.
If you get this problem  that youtube video is not showing in Mozilla Firefox but in Google chrome and safari it is showing the videos then you will have to do the following tasks.

1. Clear the cache  from Tools->Options->Advanced->Network tab Ofline web content and user data. Click on Clear Now Button.

2. Now go to Tools -> Options -> Privacy .  Click on remove individual cookies link at the last line in History section.

If you load the video by iframe just add https:// ( dont use http:// ). ie. https://www.youtube.com

This will fix your bug.

Monday, 23 September 2013

Online Income Types

If you want to be expert in IT profession, then at first you will have to make your mind that anyhow i will be IT expert.

There are lots of non IT works in online too. But those are low price than IT work hour rates. So it is better to adopt IT techniques.

If you have a rich elance or odesk profile then it will be easy to get works.

There are lots of freelancing sites in online. but you will have to work from reliable sites.