我想从HTML表单操作中获取URL。我怎样才能在PHP中获得这个?表单标签如
<form method="post" action="my.aspx? id="aspnetForm" enctype="multipart/form-data">
</form>
答案 0 :(得分:2)
您可以尝试使用DOM加载HTML,然后使用xpath提取信息:
// create a DOM document object and load your html
$doc = new DOMDocument();
$doc->loadHtml($yourHtml);
// create an Xpath selector for the document
$selector = new DOMXpath($doc);
// the following query will return all <form> elements
// you may refine it
$result = $selector->query('//form');
// get the first item (to keep the example simple)
$form = $result->item(0);
// get the value of the action attribute
$url = $form->getAttribute('action');
答案 1 :(得分:0)
您可以使用正则表达式。但我认为你可以简单地做下一步:
我认为这将有助于您学习如何解析任何HTML标签和其他内容。
答案 2 :(得分:0)
<?php
$string = <<<XML
<form method="post" action="my.aspx? id="aspnetForm" enctype="multipart/form-data"></form>
XML;
$xml = new SimpleXMLElement($string);
$att = 'action';
$attribute = $xml->form[0]->attributes()->$att; // answer
?>