donglu2008
2015-05-05 06:26
浏览 242
已采纳

如何使用PHP获取HTML元素的ID?

Pretty straight forward question and I have no idea how or if it can be done. I've searched the web for a while and haven't found anything. What I'm trying to figure out is if I can get the value of an ID in a html element. For example I want to get Joe out of this <div id="Joe">. Is there a way to do this? Any help would be greatly appreciated.

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douhao6557 2015-05-05 06:45
    已采纳

    You should be looking for DOM crawlers.. Symphony has a really nice one, and it's pretty straight forward. you'll find in their documentation all the possible ways of getting attributes out of elements.

    You'll need composer to install the package (it's a lot easier, but not a must)

    you can find the package here

    best of luck.

    已采纳该答案
    打赏 评论
  • duanbipu1720 2015-05-05 06:33

    You can get the value using

    $('.element').attr('id'); 
    

    but for this you need to add a class something like element on div

    打赏 评论

相关推荐 更多相似问题