0

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
WEBjuju
  • 5,797
  • 4
  • 27
  • 36
Chee
  • 45
  • 9

2 Answers2

0

You can get value of any attribute:

$node->getAttribute('value');

But I do not see value attribute on your h4 tag in your example.

Your explanation about $('#image-gallery-count').text($sel.data('count')); is not clear.

Update:

You php code will work if you have the value at time of parsing it:

$html='<h4 id="image-gallery-count">5</h4>';
rNix
  • 2,457
  • 1
  • 22
  • 28
0

Remember that PHP runs first, then the browser loads the HTML page executing any JavaScript it finds. Then the JavaScript that was tied to Document OnReady or similar gets loaded.

The PHP runs before the JavaScript has a chance to populate the value.

This SO link explains the page load process pretty well.

Community
  • 1
  • 1
Keypunch
  • 26
  • 5