GithubHelp home page GithubHelp logo

jaggedsoft / querypath Goto Github PK

View Code? Open in Web Editor NEW

This project forked from technosophos/querypath

0.0 1.0 0.0 3.86 MB

QueryPath is a PHP library for manipulating XML and HTML. It is designed to work not only with local files, but also with web services and database resources.

Home Page: http://querypath.org

License: Other

Makefile 0.11% PHP 99.58% Shell 0.24% HTML 0.08%

querypath's Introduction

QueryPath: Find your way.

Authors: Matt Butcher (lead), Emily Brand, and many others

Website | API Docs | VCS and Issue Tracking | Support List | Developer List | Pear channel |

This package is licensed under an MIT license (COPYING-MIT.txt).

At A Glance

QueryPath is a jQuery-like library for working with XML and HTML documents in PHP. It now contains support for HTML5 via the HTML5-PHP project.

Gettings Started

Assuming you have successfully installed QueryPath via Composer, you can parse documents like this:

require_once "vendor/autoload.php";

// HTML5 (new)
$qp = html5qp("path/to/file.html");

// Legacy HTML via libxml
$qp = htmlqp("path/to/file.html");

// XML or XHTML
$qp = qp("path/to/file.html");

// All of the above can take string markup instead of a file name:
$qp = qp("<?xml version='1.0'?><hello><world/></hello>")

But the real power comes from chaining. Check out the example below.

Example Usage

Say we have a document like this:

<?xml version="1.0"?>
<table>
  <tr id="row1">
    <td>one</td><td>two</td><td>three</td>
  </tr>
  <tr id="row2">
    <td>four</td><td>five</td><td>six</td>
  </tr>
</table>

And say that the above is stored in the variable $xml. Now we can use QueryPath like this:

<?php
// Add the attribute "foo=bar" to every "td" element.
qp($xml, 'td')->attr('foo', 'bar');

// Print the contents of the third TD in the second row:
print qp($xml, '#row2>td:nth(3)')->text();

// Append another row to the XML and then write the
// result to standard output:
qp($xml, 'tr:last')->after('<tr><td/><td/><td/></tr>')->writeXML();

?>

(This example is in examples/at-a-glance.php.)

With over 60 functions and robust support for chaining, you can accomplish sophisticated XML and HTML processing using QueryPath.

QueryPath Installers

The preferred method of installing QueryPath is via Composer.

You can also download the package from GitHub.

Composer (Preferred)

To add QueryPath as a library in your project, add this to the 'require' section of your composer.json:

{
  "require": {
    "querypath/QueryPath": ">=3.0.0"
  }
}

The run php composer.phar install in that directory.

To stay up to date on stable code, you can use dev-master instead of >=3.0.0.

Manual Install

You can either download a stable release from the GitHub Tags page or you can use git to clone this repository and work from the code.

Including QueryPath

As of QueryPath 3.x, QueryPath uses the Composer autoloader if you installed with composer:

<?php
require 'vendor/autoload.php';
?>

Without Composer, you can include QueryPath like this:

<?php
require 'QueryPath/src/qp.php';
?>

QueryPath can also be compiled into a Phar and then included like this:

<?php
require 'QueryPath.phar';
?>

From there, the main functions you will want to use are qp() (alias of QueryPath::with()) and htmlqp() (alias of QueryPath::withHTML()). Start with the API docs.

querypath's People

Contributors

technosophos avatar eabrand avatar noisan avatar tomorrowtoday avatar sandeepshetty avatar hakre avatar gdmac avatar faryshta avatar fiveminuteargument avatar danielbachhuber avatar yaph avatar zemistr avatar zackkatz avatar

Watchers

jagged avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.