Question

I need to be able to determine the type of tag i have selected with phpQuery.

So, if i have the reference of an element, how can i easily figure out its tag type?

In jquery/js tagName will suffice or prop('tagName')

But in phpQuery i cannot seem to find a straight forward function to do this..

$doc = phpQuery::newDocumentFilePHP($ftp_file['local_path']);
if(!pq('.clasToFind')->length) {
      $tagType = pq('.clasToFind')->tagName;
}

Is the best answer regex the answer here?

Was it helpful?

Solution

tagName is a DomNode property. So when you iterate:

foreach(pq('.clasToFind') as $el){
  echo $el->tagName;
}

OTHER TIPS

See my answer here: How to find tag name using phpquery?

You need to call get to point to the first element of the collection, even if it has only one element. So, your code would be something like this:

$doc = phpQuery::newDocumentFilePHP($ftp_file['local_path']);
if($doc->find('.clasToFind')->length) {
      $tagType = $doc->find('.clasToFind')->get(0)->tagName;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top