lundi 28 novembre 2016

How to get value of id from html tag to php using Dom

I want to display the value of id using xpath but what i'm getting is only the nodeName which is h4 and the nodeValue is only empty space or none.Hope anyone could help me out how since i'm not familiar with dom.I've got this idea through research.

complete result of the echo: h4-

 <?php 
           //Value of this echo is 5 which is I want to echo inside foreach
                      echo $html='<h4 id="image-gallery-count"></h4>';

                            $doc = new DOMDocument();
                            $doc->loadHTML($html);
                            $xpath = new DOMXPath($doc);

            $result = $xpath->evaluate("//h4[@id='image-gallery-count']");
                            foreach($result as $node) {

                              echo "{$node->nodeName} - {$node->nodeValue}";

                            }

//This somewhat like $count= {$node->nodeValue}
               $c = chr(64 + $count);
               $b = chr(64 + 1);
           ?>

//here is my one line code from my script that passes the value of the id with a value of 5.

$('#image-gallery-count').text($sel.data('count'));

//If i could just get the value of this id.I will use this integer to add inside $c = chr(64 + 5);.For some reason, I want to use it to iterate the forloop to display something...

Here is the loop:

@for ($i = $b; $i <= $c; $i++)                        
    <img id="image-gallery-image-{!! $i !!}" class="img-responsive" src="">
@endfor



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire