dongxu7408 2015-09-21 05:51
浏览 165

如何使用php getStr获取html标签的“name”属性?

I'm trying to find a way to get the content of this HTML attribute "name", using PHP getStr, I can't get it to work anyhow, I have already searched, but I couldn't find find something that may help me.

<input id="9d6e793e-eed2-4095-860a-41ca7f89396b.subject" maxlength="50" name="9d6e793e-eed2-4095-860a-41ca7f89396b:subject" value="" tabindex="1" class="subject required field" type="text"/>

I want to get this value into a string:

9d6e793e-eed2-4095-860a-41ca7f89396b:subject

I can get the value of a tag like this one:

<input type="hidden" name="message" value="1442814179635.Oz1LxjnxVCMMJ0QpV0wGLx4roEA="/>

With this code:

getStr($b,'name="message" value="','"');

But I can't find a way to get the attribute name of the first one?

  • 写回答

3条回答 默认 最新

  • dongqiang5541 2015-09-21 06:15
    关注

    Use regular expressions in PHP. This code should be helpful:

    <?php
    
    $str  = '<input type="hidden" name="message" value="1442814179635.Oz1LxjnxVCMMJ0QpV0wGLx4roEA="/>';
    
    //forward slashes are the start and end delimeters
    //third parameter is the array we want to fill with matches
    if (preg_match('/name="([^"]+)"/', $str, $m)) {
        print $m[1];   
    } else {
       //preg_match returns the number of matches found, 
       //so if here didn't match pattern
    }
    

    Output:

    message
    
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100