Good afternoon friends, Help get the contents of the tag namely the contents of the "rel" this text "/ question / 19613371282441896"

foreach($html - > find('div[class=question-block clickable]') as $element) { $massiv[] = $element - > plaintext; // } } 
 <div id="user_responses"> <div class="question-block clickable" rel="/question/19613371282441896"> 

    2 answers 2

    All attributes are already contained in the $element object. That is, you can get the rel attribute with $element->rel . For example:

     foreach($html - > find('div[class=question-block clickable]') as $element) { $massiv[] = $element - > plaintext; $rel = $element->rel; // } } 
    • Please try to write more detailed answers. I am sure the author of the question would be grateful for your expert commentary on the code above. - Nicolas Chabanovsky

    In your case, I would use the phpQuery library. It is simply installed using Composer .

    Assume:

     // У Вас есть такой HTML "огрызок" $html = '<div class="user id_1"><div class="question clickable" rel="/link/1"></div></div>'; // Инициализируем Singletone объект для работы с jQuery в PHP $questionsDom = phpQuery::newDocument($html); // Крутим все блоки с вопросами foreach ($questionsDom->find('div.question.clickable') as $question){ // Достаем rel аттрибут $rel = pq($question)->attr('rel'); // Выводим результат print_r($rel); } 

    phpQuery is easy to use, just like native jQuery