X
X
xaam2016-01-31 22:24:12
PHP
xaam, 2016-01-31 22:24:12

PHP Simple HTML DOM Parser how to find text?

How to find an element by text between tags? For example Employment type
Tried
$html->find([text()='Employment type'])
$html->find('Employment type')
Inserted xpath ready .//*[text()='Employment type'] by which is located in Mozilla in FirePath .....
does not work (

Answer the question

In order to leave comments, you need to log in

4 answer(s)
X
xaam, 2016-02-01
@xaam

Finally did so.

$a='';
  $j=0;
  while (strcmp('Employment type',$a)) {
   $j++;
   $a=$htm3->find('[@id=box-Details]/div[2]/div/div/dl/dt['.$j.']',0)->plaintext;
}

M
Muhammad, 2016-01-31
@muhammad_97

https://github.com/imangazaliev/didom - your code should work:

use DiDom\Document;
...
$document = new Document($html);
$elements = $documents->xpath('//*[text()="foo"]');

var_dump($elements);

I
Ilya, 2016-01-31
@glebovgin

I can’t talk about PHP Simple HTML DOM Parser, because I don’t use it, but I can say this about pure xpath:
normalize-space() is needed in order to avoid problems with spaces. It was this expression that worked for me on a pure xpath as it should.

P
Peter, 2016-01-31
@petermzg

all text blocks
$es = $html->find('text');
and then foreach

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question