Answer the question
In order to leave comments, you need to log in
How to check if an img tag has an attribute in PHP?
Tell me what I'm doing wrong?
I find the necessary img on the page in the right container, and then I need to check if they have the data-src attribute.
I do this:
foreach($data->find('.chapter-container .chapter-images img') as $img){
if(property_exists(is_array($img->getAttribute('data-src'))))
{
echo "[ есть ]";
} else {
echo "[ нет ]";
}
foreach($data->find('.chapter-container .chapter-images img') as $img){
if(property_exists($img, 'data-src'))
{
echo "[ есть ]";
} else {
echo "[ нет ]";
}
Answer the question
In order to leave comments, you need to log in
If the parser has an is method, then this is possible.
By the way, what parser are you using?
foreach($data->find('.chapter-container .chapter-images img') as $img){
if($img->is('[data-src]')) {
echo "[ есть ]";
} else {
echo "[ нет ]";
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question