PHPsu
MANUAL ZH  |  EN
     


Current Position :| index>PHP CLASS> Class: CEP Web Service

Class: CEP Web Service

FROM: AUTHOR: TIME:2008-05-30 HITS:
<?php

/**
*
* @category    CEP
* @package        CepWebService
* @version        0.1 (beta)
* @author        Deni Santos <denixsi@gmail.com>
* @copyright    Copyright (c) 2008 Deni Santos <denixsi@gmail.com>
* @license        GPL
*
* Extra :
* @generated    PHPEclipse <http://www.phpeclipse.de/>
*                Ecplise 3.3.1.1 <http://www.eclipse.org/>
*                Eclipse - an open development platform!
*                For good programmers! =) http://www.phpsu.com
*
*/
class CepWebService
{
    
/**
     * CEP - armazena o numero do CEP para efetuar a pesquisa
     *
     * @var string
     */
    
protected $_cep = '';

    
/**
     * Seta o CEP para pesquisa
     *
     * @param string $controller
     * @return CepWebService
     */
    
public function setCep($cep)

www.phpsu.com


    {
        
$this->_cep = (string) $cep;
        return
$this;
    }

    
/**
     * Retorna o CEP da pesquisa
     *
     * @return string
     */
    
public function getCep()
    {
        return
$this->_cep; phpsu.com
    }

    
/**
     * Busca as informações do CEP no webservice
     *
     * @return array
     */
    
public function find()
    {
        if(empty(
$this->_cep)) {
            
throw new Exception("Parâmetro CEP não foi definido."); welcome to phpsu.com
        }

        
$client = new SoapClient(NULL,
            array(
                
"location" => "http://www.byjg.com.br/xmlnuke-php/webservice.php/ws/cep",
                
"uri"      => "urn:xmethods-delayed-quotes", phpsu.com is a free phpscool
                
"style"    => SOAP_RPC,
                
"use"      => SOAP_ENCODED
                
)
            );

        
$result = $client->__call(
            
// Nome do método

www.phpsu.com


            
"obterLogradouro",
            
// Parâmetros
            
array(
                new
SoapParam(
                    
// CEP informado
                    
$this->_cep,
                    
// Nome do parâmentro phpsu.com is a free phpscool
                    
"parameters"
                
)
            ),
            
// Opções
            
array(
                
"uri" => "urn:xmethods-delayed-quotes",
                
"soapaction" => "urn:xmethods-delayed-quotes#getQuote"

phpsu is a phpschool


            
)
        );

        if(
strpos($result, utf8_encode('não encontrado')) !== false) {
            
$retorno = array();
        } else {
            
$retorno = explode(', ', $result);
phpsu提供的php教程

            
$retorno = array_map('trim', $retorno);
            
$retorno = array_map('strtolower', $retorno);
            
$retorno = array_map('ucwords', $retorno); do you kown phpsu.com?
        }

        return
$retorno;
    }
}
?>

File: example.php


<?php

    
include 'CepWebService.php';
    
    
$cep = new CepWebService();
    
$result = $cep->setCep('80730-400')

phpsu is a phpschool


                  ->
find();
    
    echo
"<pre>";
    
print_r($result);
    echo
"</pre>";
    
?>

TITLE:Class: CEP Web Service
Copyright 2008 The PHPsu All rights reserved. This mirror generously provided by: .Hp Inc.
Last updated: Fri Jun 6 22:59:01 GMT-8 2008