PHP DOM Xpath - search for class name

24,288

You should be able to do

$xpath->query('//div[contains(@class,"precodet")]');
Share:
24,288
yoda
Author by

yoda

Freelance Web Developer

Updated on July 09, 2022

Comments

  • yoda
    yoda almost 2 years

    Possible Duplicate:
    XPath: How to match attributes that contain a certain string

    I'm trying to parse some html with PHP DOM Xpath, but I'm having problems searching for a class name when the element has more than one. I found that if I use the hole attribute value like

    $xpath->query('//div[@class="precodet precodeturgente"]'); 
    

    it works, but if I do

    $xpath->query('//div[@class="precodet"]');
    

    it won't give me the node value. Sometimes there's only one class, others there are more than one, so what I want to know is if there's a way to search for a single class name.

  • Maxim Krizhanovsky
    Maxim Krizhanovsky almost 11 years
    this would match any class that begins with precodet, for example XprecodetY would be matched
  • KoviNET
    KoviNET over 7 years
    What would be solution for matching exactly this class, but not any other class that begins with "precodet" ?