PHP Classes

Webdice Utilities: Send requests with Curl and parse and write XML

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 328 All time: 7,164 This week: 673Up
Version License PHP version Categories
easy-curl-request 0.2.3Free for non-comm...5.4XML, HTTP, PHP 5
Description 

Author

This package can perform HTTP requests using the CURL extension, send files via that, and can set the parameters and options to send HTTP GET and POST requests using the CURL extension functions.

The names of the options are the same as the ones defined in the PHP documentation of the CURL extension.

It also contains a XML parser class which can read an XML file or string and return the document as an array or JSON string. It is also can convert an array and save to a XML file or just return an XML string.

Picture of István Dombi
  Performance   Level  

 

Example

<?php / * Creaated by Dombi István <dombi.istvan@webdice.hu> <dombiistvan28@gmail.com> */ require_once dirname(__FILE__) . '/vendor/autoload.php';

/ * Example GET request */ $request = new Webdice\Utilities\Curl\Request('http://example.com', array('returntransfer' => 1)); $request->get(array('something' => 'value', 'other' => 'value2')); //$request->debug();

/ * Example POST request */ $request = new Webdice\Utilities\Curl\Request(

'http://posttestserver.com/post.php?dir=webdice',
array('returntransfer' => 1)

); $request->post(array('something' => 'value', 'other' => 'value2')); //$request->debug();

/ * Exmaple POST request WITH FILE TRANSFER */ $file = realpath('test.jpg'); $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $url = substr($url,0,strpos($url,'examples.php')); $request = new Webdice\Utilities\Curl\Request(

$url . 'file_receive.php',
array(
    'safe_upload' => false
)

); $request->post(array(

'file' => '@' . $file,
'post' => 'value'

));

/ * Example CUSTOM REQUEST */ $request = new Webdice\Utilities\Curl\Request('http://example.com', array(

'returntransfer' => 1,
'customrequest' => 'PUT'

)); $request->send(); // and get response of request $request->getResponse(); // or get specified header $request->getResponseHeader('Content-type'); // or get all headers $request->getResponseHeaders();


Details

README

This Repository contains useful classes to make some of your work much easier. Currently cURL Request and Xml Parser/Writer classes, with example codes.

  • CURL Request
  • XML file/string Parser/Writer

What is this repository for?

  • This repository for to have an easy group of code to the usually not easy progresses
  • 0.2.0

How do I get set up?

  • Init, install if you don't have it already or update composer
  • copy curl_examples.php, curl_file_receive.php, xml_parser_example.php, test.jpg and test.xml files to your web root, and run
  • Open the example file you want to see (curl,xml)
  • use and enjoy

CURL Examples

  • Example GET Request
#!php
$request = new Webdice\Utilities\Curl\Request('http://example.com' , array('returntransfer' => 1));
$request->get(array('something' => 'value', 'other' => 'value2'));

  • Example POST request
#!php
$request = new Webdice\Utilities\Curl\Request('http://posttestserver.com/post.php?dir=webdice' , array('returntransfer' => 1));
$request->post(array('something' => 'value', 'other' => 'value2'));
  • Example POST request with file upload
#!php
$file = realpath('test.jpg');
$request = new Webdice\Utilities\Curl\Request('http://things.local/curl_file_receive.php' , array('safe_upload' => false));
$request->post(array('file' => '@' . $file,'post' => 'value'));
  • Example Custom request
#!php
$request = new Webdice\Utilities\Curl\Request('http://example.com' , array('returntransfer' => 1,'customrequest' => 'PUT'));
$request->send();

XML Parser examples

  • Example: Pass xml file to parse
#!php
$parser = new \Webdice\Utilities\Xml\Parser('test.xml');
$arr = $parser->parse();
var_dump($arr);

  • Example: Parse xml content directly
    #!php
    $parser = new \Webdice\Utilities\Xml\Parser();
    $arr = $parser->parseString('<root_element><items><item attributex="1">dsa</item></items></root_element>');
    var_dump($arr);
    
  • Example: Change the return data keys !before parse method
    #!php
    $parser = new \Webdice\Utilities\Xml\Parser('test.xml');
    $parser->changeNodeConfig('element_name', 'children_elements', 'attributes');
    $arr = $parser->parse();
    var_dump($arr);
    
  • Example: Change parsed response format to JSON 
    #!php
    parser = new \Webdice\Utilities\Xml\Parser();
    $parser->changeNodeConfig('element_name', 'children_elements', 'attributes');
    $arr = $parser->parse('test.xml', \Webdice\Utilities\Xml\Parser::TYPE_JSON);
    
  • Example: Write xml file from array (recursively)
    #!php
    $parser = new \Webdice\Utilities\Xml\Parser();
    $content = $parser->toXml(array(
    array(
        'node' => 'valami',
        'value' => '',
        'children' => array(
            array(
                'node' => 'valami1',
                'value' => 'dsa',
                'children' => array(
                    array(
                        'node' => 'valami2',
                        'value' => 'dsa1',
                        'children' => array(
                            array(
                                'node' => 'valami3',
                                'value' => 'dsa2',
                                'attributes' => array(
                                    'dd3' => 7,
                                    'dd4' => 8
                                )
                            ), array(
                                'node' => 'valami4',
                                'value' => 'dsa3',
                                'attributes' => array(
                                    'dd3' => 9,
                                    'dd4' => 10
                                )
                            ), array(
                                'node' => 'valami5',
                                'value' => 'dsa4',
                                'attributes' => array(
                                    'dd3' => 11,
                                    'dd4' => 12
                                )
                            ),
                        ), 
                        'attributes' => array(
                            'dd3' => 5,
                            'dd4' => 6
                        )
                    )
                ), 
                'attributes' => array(
                    'dd3' => 3,
                    'dd4' => 4
                )
            )
        ), 
        'attributes' => array(
            'dd1' => 1,
            'dd2' => 2
        )
    )
    ), 'temp.xml');
    
    
### Who do I talk to? ###

* Repo owner or admin
* Write an email to <dombi.istvan@webdice.hu>

  Files folder image Files (13)  
File Role Description
Files folder imageCurl (2 files)
Files folder imageXml (2 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file curl_examples.php Example Example script
Accessible without login Plain text file curl_file_receive.php Example Example script
Accessible without login Plain text file examples.php Example Example script
Accessible without login Plain text file file_receive.php Example Example script
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Image file test.jpg Data Auxiliary data
Accessible without login Plain text file test.xml Data Auxiliary data
Accessible without login Plain text file xml_parser_example.php Example Example script

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 84%
Total:328
This week:0
All time:7,164
This week:673Up