Monthly Archives: February 2015

PHP and Web Service

I will be discussing a very simple example of using web services with PHP. The Web Service consumes a zip code (US zip code in our example) and returns an array containing the City, State, Area Code and Time Zone. To keep things simple, I will only convert Zip Code into City and State.
Web Service used: http://www.webservicex.net/uszip.asmx?op=GetInfoByZIP
Web Service WSDL: http://www.webservicex.net/uszip.asmx?WSDL
Programming Language: PHP
Framework: WordPress. Valid for any framework using PHP.
PHP APIs: SOAP Client, XML Parser
The code follows:
$zipcode = $_POST['zipcode']; //I am fetching the zip code via an ajax call from an user input
$url = "http://www.webservicex.net/uszip.asmx?WSDL";
$client = new SoapClient($url); //create a new SOAP client object and feed it with the WSDL URL
//$fns = $client->__getFunctions(); //You can dump the available functions using the getFunctions method
//var_dump($fns); //dumping the functions reveal the method definitions
$res = $client->GetInfoByZIP(array('USZip' => $zipcode)); //use the GetInfoByZIP method passing the USZip as an array parameter
$parsedXML = simplexml_load_string($res->GetInfoByZIPResult->any); //the returned value is in XML format which can be easily parsed using PHP XML parser
$city = $parsedXML->Table[0]->CITY; //fetch the city
$state = $parsedXML->Table[0]->STATE; //fetch the state

The output of the line var_dump($fns) is attached below.Method dump
As you can see, the GetInfoByZIP method has an array parameter and returns a complex type GetInfoByZIPResponse. The same can be verified from the WSDL mentioned in this post. This example can be used with any kind of web service and scaled as per business requirements.
Hope this helps! Please leave your valuable comments and let me know what you think.

jQuery and HTML anchor tag

Quick tip for avoiding the annoying hashtag (#) that gets appended to the page url when using HTML anchor tag combined with jQuery.
A very basic example:
<a id="this-is-a-demo" href="#">This is a demo</a>
jQuery( '#this-is-a-demo' ).on('click', function() {
//your own custom logic on anchor tag click
return false; //prevents the hashtag from appending to the page url
});

Hope this helps. Please leave a comment if there is a better way to achieve the same result.

WordPress and Owl Carousel

In this post, I would like to discuss a certain behavior of OwlCarousel I noticed with respect to the ‘responsive’ option of the plugin.
The below code snippet doesn’t output one single column on mobile devices if there is only one post/item to display.
responsiveClass:true,
responsive:{
0:{
items:1,
},
768:{
items:echo number of columns,
}
}

Instead, a slight change to the script as shown below works perfectly fine.
responsiveClass:true,
responsive:{
0:{
items:1.0000000000001,
},
768:{
items:echo number of columns,
}
}

Please leave a comment if you faced similar issue and what kind of resolution you came up with.

Knowledge Nugget 1

Quick tip for those who sometimes face the issue of not able to see any information regarding Completed workflows published in ‘dmc_completed_workflow‘.

For majority of the cases, the issue is with the Documentum job ‘dm_WfReporting‘ not running in background or returning exception. So, this can be one of the root causes for the failure of any customization that consumes data from dmc_completed_workflow.

I had a similar experience and wanted to capture it in this post for ready reference.