dongqiao2077 2011-05-16 23:42
浏览 60
已采纳

用于查找多行表单数据的正则表达式(php)

I try (without success) to make a regex for find a submit button even if button code is in one two or more lines.

I use now this patter

/<(button|input)(.*type=['\"](submit|button)['\"].*)?>/i

and works fine if the button code is in one line

<input type="submit" name="mybutton" class="button_class" value="Submit" title="Click Me" />

I want to make it work if my button code look like

<input type="submit" name="mybutton"

class="button_class" value="Submit"

title="Click Me" />

Thanks

  • 写回答

3条回答 默认 最新

  • dongyou2635 2011-05-16 23:48
    关注

    Don't use a regular expression to parse HTML.

    RegEx match open tags except XHTML self-contained tags

    Learn xpath, and use a parser.

    EDIT Added some code to insert before.

        $dom = new DOMDocument();
        @$dom->loadHTML($html);
        $x = new DOMXPath($dom);        
        foreach($x->query("//input[@type='submit']") as $node)
        {
             $newNode = $dom->createElement("img");
             $newNode->setAttribute("src","/loading.gif");
             $node->insertBefore($node);    
        }
        $output = $dom->saveHTML();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类