Code Monkey home page Code Monkey logo

php-html-parser's People

Contributors

alcaeus avatar blaaat avatar cybrox avatar gufran avatar iamsab avatar lukasros avatar paquettg avatar rhrebecek avatar scrutinizer-auto-fixer avatar ssfinney avatar sunra avatar thesoftwarefanatic avatar thiagotalma avatar vipercz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-html-parser's Issues

when searching for child returns child and texts

When I search for tr td: nth-child (1) returns all elements and when I search for tr td [1] does not return anything, am I doing something wrong here? with PhpSimple works normal.

$dom = new Dom;
$dom->load('HTML TABLE');
$tds =  $dom->find('tr td:nth-child(1)');

Returns
desktop screenshot 2018 12 10 - 02 21 18 71

with
$tds = $dom->find('tr td[1]');
returns nothing.

I edited the file Selector.php, I added this after line 172

$return = [];

after line 185

$nth = $node->find($rule['tag'], $rule['key']);
if ($nth) {
   $return[] = $nth;
}

and line 188 of

return []; 

to

return $return; 

and now works with tr td[1] selector

Does not this selector work or am I doing something wrong?

Wrapping a dom child in a template

I want to wrap a child element of a site with an template.

$dom = new Dom;
$dom->load('site.html');
foreach($dom->find('node') as $node) {
   $tmpl = new Dom;
   $tmpl->load('template.html');
   $tmpl->find('*[id=container])[0]->addChild($node)
   $node->getParent()->replaceChild($node->id(),$tmpl->root);
}

However I think (even if the replaceChild method works) the output will not be as expected. We add $node as child to the root of $tmpl. But what happens, when I replace $node with $tmpl?

Will $node, as child of $tmpl also get deleted? I am thinking about what is passed by value or reference and PHP handles that often very unclear ...

For wrapping also a custom function could be considered, if the above question answers with yes.

Release New Version

Would you please release a new version containing the most recent yet unpublished fixes? 8bda319 would make this project compatible with PHP 7.3.

[Proposal] Fork paquettg/string-encode and fix iconv notices

I assume paquettg/string-encode is unmaintained as well.
Can we / I fork this and switch dependencies?

Currently the iconv call generates a notice and then a Exception is generated as well. I would like to prevent the notice (by either suppressing or temporary replacing the error_handler?).

Loading a page with an incorrect character set in a meta tag now generates notices.
Example code with notice:

$dom = new Dom; 
$dom->load('http://www.sanderback.us/test-html-parser.html'); 
foreach ($dom->find('a') as $link) {
	$x = $link->href;
}

Count issue with PHP 7.2.3

Doesn't work with 7.2.3

count(): Parameter must be an array or an object that implements Countable

Selector.php on line 171

This is where it's failing :
if (count($rule['tag']) > 0 && count($rule['key']) > 0 &&

count can't be used to count non-countable types from 7.2

Check here

[Proposal] Method/option to update/add charset meta tag

When importing and exporting HTML the charset might be changed, but the meta charset tag is not. Resulting in invalid output. I suggest either creating a method which updates/adds an meta charset tag or updating an existing tag automatically on import (with option?)

[REQUEST] Method text return child text

I would suggest next update will have this feature.

DOM:

<div class="parent">
   <div class="child1">
       <div class="child2">im here</div>
   </div>
</div>

recent:
$dom->find('.parent')->text return empty

hopefully will like jquery text()
which is like:
strip_tags($dom->find('.parent')->innerHtml)

how do you think about this?

AbstractNode.php, wrapper for Tag.php setAttributes

Can't do

$div = $form->find('div');
$div->setAttributes([
   'id' => 'main'
   'class' => 'block'
]);

as wrapper for this function is missing.

Also the AbstractNode class has a $attr property which I think is not necessary as attributes are stored in Tag class.

Innernode->replaceChild()

    /**
     * Removes the child with id $childId and replace it with the new child
     * $newChild.
     *
     * @param int $childId
     * @param AbstractNode $newChild
     * @throws ChildNotFoundException
     */
    public function replaceChild($childId, AbstractNode $newChild)
    {
        $oldChild                         = $this->getChild($childId);
        $keys                               = array_keys($this->children);
        $index                              = array_search($childId, $keys, true);
        $keys[$index]                   = $newChild->id();
        $this->children                  = array_combine($keys, $this->children);
        $this->children[$newChild->id()] = $newChild;
        unset($oldChild);
    }

This method has some conceptional errors (or how to call that?). The biggest mistake is, to set directly the node in the children array. In other parts the structure of children is follow:

$children = [
   hash => [
      'prev' => hash,
      'next' => hash,
      'node' => HtmlNode,
   ],
   [...]
]

When we look in the tests, its clear, that this coding mistake can not be detected.

My approach for this method simply would be:

$this->getChild($childId); // indirect check if child exitsts
$this->children[$childId]['node'] = $newChild;

Or do we have to explicitly unset the old child?

P.S some typo found

/**
     * Attempts to get the previous child.
     *
     * @param int $id
     * @return AbstractNode
     * @uses $this->getChild()
     * @throws ChildNotFoundException
     */
    public function previousChild($id)
    {
        $child = $this->getchild($id); // typo here: should be $this->getChild()
        $next  = $this->children[$child->id()]['prev'];

        return $this->getChild($next);
    }

Twig template rendering

I am rendering a twig template and modifying the html. I can modify the html but it breaks the twig string.

After i load the .twig file this div:

<div {{ not variable_name ? 'class="class_name"' }} id="id_name">

turns to:

<div {{ not variable_name ? 'class="class_name" }} id="id_name">

'class="class_name"<=== the single quote after the double quotes is lost.

I wanted to know if there is an option to set for this purpose or this case is not handled.

Thanks!

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.