Topic: PHP examples

Hi,
These are working for me, feel free to use them at your own risk

class MSSoapClient extends SoapClient {
    private $namespace;
    function __doRequest($request, $location, $action, $version) {
       

        $request = preg_replace('/<ns1:(\w+)/', '<$1 xmlns="'.$this->namespace.'"', $request, 1);
        $request = preg_replace('/<ns1:(\w+)/', '<$1', $request);
        $request = str_replace(array('/ns1:', 'xmlns:ns1="'.$this->namespace.'"'), array('/', ''), $request);
       
        // parent call
        return parent::__doRequest($request, $location, $action, $version);
    }
    function setNamespace($sNamespace)
    {
        $this->namespace=$sNamespace;
    }
   

To make a new customer - I'm only you can extend the function to add other details to the record.

function newKashflowCustomer($soapClient,$idAccount,$name,$address,$town,$postcode,$country,$email)
{
    //returns customer id if ok else 0
   
    $today = date("Y-m-d",mktime());
   
    $customerArray = array(
        "CustomerID"=>"",
        "Code"=>"",
        "Name"=>"$name",
        "Contact"=>"",
        "Telephone"=>"",
        "Mobile"=>"",
        "Fax"=>"",
        "Email"=>"$email",
        "Address1"=>"$address",
        "Address2"=>"",
        "Address3"=>"$town",
        "Address4"=>"$country",
        "Postcode"=>"$postcode",
        "Website"=>"",
        "EC"=>"0",
        "Notes"=>"",
        "Source"=>"",
        "Discount"=>"0",
        "ShowDiscount"=>"0",
        "PaymentTerms"=>"0",
        "ExtraText1"=>"1",
        "ExtraText2"=>"1",
        "CheckBox1"=>"1",
        "CheckBox2"=>"1",
        "Created"=>"$today",
        "Updated"=>"$today");
   
    $args = array ("UserName"=>"your username here", "Password"=>"your password here","custr"=>$customerArray);
    $oResponse = $soapClient->InsertCustomer($args);
    //handle any errors
    if($oResponse->Status != "OK")
    {
        echo $oResponse->StatusDetail;
        $return = 0;

    }
    else
    {
        $id = $oResponse->InsertCustomerResult;
       
        $return = $id;
       
    }
    return $return;
}

Re: PHP examples

Hey its very interesting, I am search for this.


Thank you very much.

3 (edited by Joneswilliamsc 2010-05-29 03:46)

Re: PHP examples

Well its really very nice. But I having problem with it. I suffer with this program only once. When at the first time I run this program than its showing me error. But when I run it twice its working proper. Why its happen so I don't know. But now I am happy that its working fine. Its really very nice program.

Mistakes are the portals of discovery.

Re: PHP examples

A very good function

Thank you

Re: PHP examples

In programming, a string is a sequence of letters, symbols, characters and arithmetic values or combination of all tied together in single or double quotes. For example, "I Love PHP", "10", '100.01', "", etc are all examples of strings.

6 (edited by FreestyleCrafter 2012-09-05 08:22)

Re: PHP examples

It looks like java xD

 package com.freestylecrafter.quickweb;

import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
import android.webkit.*;
import android.widget.*;
import java.security.*; 

public class Info extends Activity
{
   
    }

Re: PHP examples

class MSSoapClient extends SoapClient {
    private $namespace;
    function __doRequest($request, $location, $action, $version) {
       

        $request = preg_replace('/<ns1:(\w+)/', '<$1 xmlns="'.$this->namespace.'"', $request, 1);
        $request = preg_replace('/<ns1:(\w+)/', '<$1', $request);
        $request = str_replace(array('/ns1:', 'xmlns:ns1="'.$this->namespace.'"'), array('/', ''), $request);
       
        // parent call
        return parent::__doRequest($request, $location, $action, $version);
    }
    function setNamespace($sNamespace)
    {
        $this->namespace=$sNamespace;
    }
   
} 

Just curious, the class SoapClient from which MSSoapClass is being extended has to be included right? If so, from where?