1

I have this script in Symfony 2:

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\DomCrawler\Crawler;

class MyController extends Controller
{
....
foreach($crawler->filter('[type="text/css"]') as $content){
/* make things */
}
foreach($crawler->filter('[rel="stylesheet"]') as $content){
/* make things */
}

¿can $crawler->filter accept various conditions and do it in one foreach? For example:

foreach($crawler->filter('[rel="stylesheet"] OR [type="text/css"]') as $content){
/* make things */
}
Avara
  • 1,753
  • 2
  • 17
  • 24

2 Answers2

2

The filter function takes a standard CSS selector, so:

foreach ($crawler->filter('[rel="stylesheet"],[type="text/css"]') as $content) {
   /* make things */
}

Should do the job.

COil
  • 7,201
  • 2
  • 50
  • 98
0

AFAIK this is not possible but you can do this:

$crawler->filter('[rel="stylesheet"]')->addAll($crawler->filter('[type="text/css"]'));

This should resolve your problem.

Additionaly, you can also filter with xpath.

Markus
  • 440
  • 2
  • 10