John Davidson

domcrawler - Symfony 2 Dom Crawler: how to get only text() in Element

0 comments
Message:


Using Dom Crawler to get only text (without tag).



$html = EOT<<<
<div class="coucu">
Get Description <span>Coucu</span>
</div>
EOT;

$crawler = new Crawler($html);
$crawler = $crawler->filter('.coucu')->first()->text();


output: Get Description Coucu



I want to output (only): Get Description



UPDATE:



I found a solution for this: (but it's really bad solution)



...
$html = $crawler->filter('.coucu')->html();
// use strip_tags_content in https://php.net/strip_tags
$html = strip_tags_content($html,'span');


My Answer:
$html = '

Hello World

';

$crawler = new Crawler($html);

$text = $crawler->filter('div')->text();

echo $text; // Output: Hello World

Rate this post

5 of 5 based on 2713 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us