terça-feira, 27 de abril de 2010

Sobre desenvolvimento de software

The unique characteristics of the open-source approach distinguish it from existing
commercial software development practices. Participants in open source are globally and virtually distributed, and usually never meet face-to-face. These geographically
distributed participants successfully coordinate software development without traditional mechanisms, such as design processes, schedules, etc.

Yukika Awazu & Kevin C. Desouza - Open Knowledge Management: Lessons From the Open Source Revolution

sexta-feira, 23 de abril de 2010

Obtendo uma página com file_get_contents e stream context

Com o código abaixo eu consigo fazer uma requisição GET passando por um proxy. Com stream context fica bem mais simples que montar a string no formato do HTTP.


$authProxy = base64_encode($this->proxyUser . ":" . $this->proxyPasswd);
// Création des options de la requête
$opts = array(
'http' => array (
'method'=>'GET',
'proxy'=>'tcp://10.68.15.240:3128',
'request_fulluri' => true,
'header'=>"Proxy-Authorization: Basic $authProxy"
)
);
// Création du contexte de transaction
$ctx = stream_context_create($opts);
// Récupération des données
$content = file_get_contents($this->url . "?" . $queryString, false, $ctx);

quinta-feira, 22 de abril de 2010

Exemplo de uso do simplexml_load_string


$objXml = simplexml_load_string($xml);

$perfis = $objXml->xpath("/methodResponse/params/param/value/struct/member[name='roles']/value/array/data/value[starts-with(string, 'MU_') || starts-with(string, 'Estado ')]/string");

foreach($perfis as $perfil)
{
$nms_perfis[] = strip_tags($perfil[0]->asXML());
}

Transformar um XML em um objeto PHP

O PHP possui funções para fazer parse de um XML, 'xml_parse' etc. Entretanto uma maneira mais rápida de carregar um XML é usando 'simplexml_load_file' (link pro php.net).

Ou melhor ainda, 'simplexml_load_string'. Ambas retornam um SimpleXMLElement.