2

How to extract untagged elements with symfony dom crawler. For example in the sample html below I want to extract Hello World.

<strong>title</strong>Hello World<strong>Sub-Title</strong><div>This is just stuff</div>
M Sh
  • 429
  • 2
  • 4
  • 11

2 Answers2

1

i have a better way for you

$ExtractText = $crawler->filter('strong')->eq(1)->text();

this pretty much get the tag of the index 1 as your title is index 0

MAV
  • 29
  • 8
0

You could do this easily with PHP DOM ;)

$dom = new DOMDocument();
$dom->loadHTML('<strong>title</strong>Hello World<strong>Sub-Title</strong><div>This is just stuff</div>');
$xpath = new DOMXPath($dom);
// use the fact that PHP DOM wraps everything into the body and get the text()
$entries = $xpath->query('//body/text()');
foreach ($entries as $entry) {
    echo $entry->nodeValue;
}
Marc
  • 3,683
  • 8
  • 34
  • 48