简体   繁体   English

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

[英]How to Get the ID of an HTML element using PHP?

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. 我要弄清楚的是,是否可以在html元素中获取ID的值。 For example I want to get Joe out of this <div id="Joe"> . 例如,我想让Joe脱离<div id="Joe"> Is there a way to do this? 有没有办法做到这一点? Any help would be greatly appreciated. 任何帮助将不胜感激。

You should be looking for DOM crawlers.. Symphony has a really nice one, and it's pretty straight forward. 您应该在寻找DOM搜寻器。Symphony有一个非常不错的应用程序,而且非常简单。 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. 祝你好运。

You can get the value using 您可以使用获得价值

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

but for this you need to add a class something like element on div 但是为此,您需要在div上添加一个类似于element的类

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM