duanqiongniu1469
2017-07-07 02:15
浏览 126
已采纳

PHP echo回显来自HTML的输入值

I need to echo Values from input fields. Preferably $var name can be same as input fieldname. Sample: echo $yesRedirect; Should output: No

<?php
$html = array('<input type="text" name="yesRedirect" id="yesRedirectfunction" value="No">',
'<input type="text" name="noRedirect" id="noRedirectfunction" value="Yes">',
'<input type="text" name="quickcheck" id="quickcheckfunction" value="No">');

$result = array();

foreach ($html as $name) {
$dom = new DomDocument;
$dom->loadHTML($name);
var_dump($dom) . "
";

//echo $dom->getAttribute('name') . "
";
//echo $dom->getAttribute('value') . "
";
}

echo $yesRedirect; // Should output: No
echo $noRedirect;  // Should output: Yes
?>

How can I simply echo input value? Is there any other way? Thank you for helping.

图片转代码服务由CSDN问答提供 功能建议

我需要从输入字段回显值。 $ var 名称最好与输入字段名相同。 示例: echo $ yesRedirect; 应输出:

 &lt;?php 
 $ html = array('  &lt; input type =“text”name =“yesRedirect”id =“yesRedirectfunction”value =“No”&gt;',
'&lt; input type =“text”name =“noRedirect”id =“noRedirectfunction”value =  “是”&gt;',
'&lt; input type =“text”name =“quickcheck”id =“quickcheckfunction”value =“No”&gt;'); 
 
 $ result = array(); \  n 
foreach($ html as $ name){
 $ dom = new DomDocument; 
 $ dom-&gt; loadHTML($ name); 
var_dump($ dom)。  “
”; 
 
 // echo $ dom-&gt; getAttribute('name')。  “
”; 
 // echo $ dom-&gt; getAttribute('value')。  “
”; 
} 
 
echo $ yesRedirect;  //应该输出:No 
echo $ noRedirect;  //应该输出:是
?&gt; 
   
 
 

如何简单地回显输入值? 还有其他方法吗? 谢谢你的帮助。

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

1条回答 默认 最新

  • douhuan6305 2017-07-07 03:41
    已采纳

    I got the results as wanted with this code below:

    <?php
    
    $html = array('<input type="text" name="yesRedirect" id="yesRedirectfunction" value="No">',
                  '<input type="text" name="noRedirect" id="noRedirectfunction" value="Yes">',
                  '<input type="text" name="quickcheck" id="quickcheckfunction" value="No">');
    
    $result = array();
    
    foreach ($html as $name) {
    $name = str_replace('"','',$name);
    $name = str_replace('>','',$name);
    
    $varname = explode("name=", $name);
    $arrname = explode(' ',trim($varname['1']));
    
    $varvalue = explode("value=", $name);
    $arrvalue = explode(' ',trim($varvalue['1']));
    
    $result[$arrname[0]] = $arrvalue[0];
    
    }
    
    echo $result['yesRedirect'];
    echo $result['noRedirect']; 
    echo $result['quickcheck']; 
    ?>
    
    打赏 评论

相关推荐 更多相似问题