简体   繁体   English

下拉值和 php

[英]Drop down values and php

I have a drop down menu/list in a html page.我在 html 页面中有一个下拉菜单/列表。 These contain links as values and labels..这些包含作为值和标签的链接..

<form name="form1" method="post" action="">
  <label>mylinks
  <select name="select">
    <option value="a.html">a</option>
    <option value="b.html">b</option>
    <option value="c.html">c</option>
  </select>
  </label>

I am trying to find a way how to get these links out of the form and in to the php page like $a = a $b = b and so on, so i can use it as an external link out of the drop down in a hidden page for checking my links if working or not.我正在尝试找到一种方法如何将这些链接从表单中取出并进入 php 页面,如 $a = a $b = b 等等,所以我可以将它用作下拉菜单中的外部链接一个隐藏页面,用于检查我的链接是否有效。 These links change from time to time..这些链接不时更改..

The form contains 3 values.该表单包含 3 个值。 a.html, b.html and c.html. a.html,b.html 和 c.ZFC35FDC70D5FC69D2698883AE22 if I have this page opened and can select one of three I go to a page.如果我打开此页面并且可以将 select 三个 I go 之一转到一个页面。 But I would like to have a place in this page that will echo the results of all 3 values out of the drop down as:但我想在这个页面中有一个位置,它将所有 3 个值的结果从下拉列表中回显为:

// This is not code. This is to show what I need
if value1 is <option value="a.html">a</option> then 
echo '<a href=' .value1.'>a</a>';
so i could have result at the bottom

//This is the result
<a href="a.html">a</a>
<a href="b.html">b</a>
<a href="c.html">c</a>

My problem is how to extract the values from the form and echo them as href.我的问题是如何从表单中提取值并将它们作为 href 回显。 Is there a way with php or do I have to do a function or something else?有没有办法使用 php 还是我必须做 function 或其他什么? Hope this helped.希望这有帮助。

You can try this example, (it works as I understood to your question)你可以试试这个例子,(它就像我对你的问题的理解一样)

<!DOCTYPE html>
<html>
<head>
    <title>Kostas Example</title>
</head>
<body>

    <form name="form1" action="" method="post">
        <label>My Links</label>
        <select name="select">
            <option value="a.html">Document a</option>
            <option value="b.html">Document b</option>
            <option value="c.html">Document c</option>
        </select>
        <button type="submit">Submit</button>
    </form>

    <?php 

        if(isset($_POST['select'])) {
            $link = $_POST['select'];
            echo "<a href='$link'>Document " . $link . "</a>";
        }

    ?>

</body>
</html>

This in not an answer.这不是答案。 Just were I am.只是我。 I entered the string of first html so it can be easier to work on...我输入了第一个 html 的字符串,这样可以更轻松地处理...

 <?php

$html = '<form name="form1" method="post" action="">
  <label>my_links
  <select name="select">
    <option value="a.html">a</option>
    <option value="b.html">b</option>
    <option value="c.html">c</option>
  </select>
  </label>';
echo $html;
$html2 = str_word_count($html, 1);
print_r($html2);
$count = 0;
foreach ($html2 as $value[$count]){
$count = $count + 1 ;
print $count."<br>";
//print "<br>";
$match_index = array_search("value", $value);
echo $match_index;
}


?> 

After a lot of search on the internet I came to an answer for this problem.在互联网上进行了大量搜索后,我找到了这个问题的答案。 This is the code这是代码

 <?php

$html = '<form name="form1" method="post" action="">
  <label>my_links
  <select name="select">
    <option value="a.html">a</option>
    <option value="b.html">b</option>
    <option value="c.html">c</option>
  </select>
  </label>';
echo $html;
echo "<br>";
$html2 = str_word_count($html, 1);
//print_r($html2);
$count = 0;
foreach ($html2 as $value){
$a[$count] = $html2;
//echo a[$count];
$match_index = array_search("value", $html2[$count]);
//echo $match_index;
$count = $count + 1 ;
//print $count."<br>";
}
//print "my result = ".$count."<br>";
foreach(range(0, $count) as $num){
    if ("value" == $html2[$num]){
    $a = $html2[$num +1];
    $b = $html2[$num + 2];
    echo '<a href="'.$a. '.'. $b .'">'. $a .'<br>';
    }else{
    echo "";
    }
}
?> 

There are a problem here.这里有一个问题。 If my link has two or more word separated with a space then I will not have in the end ".html" as I expect but ".second word".如果我的链接有两个或多个用空格分隔的单词,那么最后我将不会像我期望的那样有“.html”,而是“.second word”。 Not good.不好。 I am sure that code like this exist but I haven't found it yet.我确信存在这样的代码,但我还没有找到它。 If anyone has an idea please add a comment..如果有人有想法,请添加评论..

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

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