PHP如何将数组的内容循环成 “链接”+“下拉选择”的样式

WBOY
Release: 2016-06-13 13:28:35
Original
940 people have browsed it

PHP怎么将数组的内容循环成 “链接”+“下拉选择”的样式
自己写的一个循环:

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<?php $videolist = "优酷{span}youku{span}地址1{sl}地址2{sl}地址3{li}土豆{span}tudou{span}土豆地址{li}新浪{span}sina{span}新浪地址1{sl}新浪地址2{sl}新浪地址3{li}";

$list = explode('{li}',$videolist);
    $palylist = '';
    for($i=0;$i<count($list);$i++){
        $video = explode('{span}',$list[$i]);
        if(empty($video[0])) continue ;
        if(empty($video[1])) continue ;
        $play = $i+1;
        //$url = $video[1];
        $palylist .="<a href=\"&play={$play}\" target=\"_blank\">{$video[0]}  ";
        }
        echo $palylist;

?>

Copy after login


以上循环出来的结果是:
HTML code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<a href="&play=1" target="_blank">优酷</a>  <a href="&play=2" target="_blank">土豆</a>  <a href="&play=3" target="_blank">新浪</a>

Copy after login


请问如何循环成如下样式:
HTML code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
    <select name="youku">
      <option>优酷</option>
      <option value="地址1">第一集</option>
      <option value="地址2">第二集</option>
      <option value="地址3">第三集</option>
      </select>
     <a href="%E5%9C%9F%E8%B1%86%E5%9C%B0%E5%9D%80">土豆</a>
     <select name="sina">
      <option>新浪</option>
       <option value="地址1">第一集</option>
      <option value="地址2">第二集</option>
      <option value="地址3">第三集</option>
      </select>

Copy after login


------解决方案--------------------
PHP code
$videolist = "优酷{span}youku{span}地址1{sl}地址2{sl}地址3{li}土豆{span}tudou{span}土豆地址{li}新浪{span}sina{span}新浪地址1{sl}新浪地址2{sl}新浪地址3{li}";
$ar=preg_split('/\{li\}/',$videolist,-1,PREG_SPLIT_NO_EMPTY); 
$html='';
$j=array(0=>'第一集',1=>'第二集',2=>'第三集');
foreach($ar as $v){
     $arr=preg_split('/\{.*?\}/',$v)  ;
     if(count($arr)>3) {
           $html.='<select name="'.$arr[1].'">'."\n" ; 
         $html.='<option>'.$arr[0].'</option>'."\n";
        
          foreach(array_slice($arr,2) as $kl=>$vl) $html.='<option value="'.$vl.'">'.$j[$kl].'</option>'."\n";         
     }    else{
            $html.='<a href="'.%24arr%5B2%5D.'">'.$arr[0].'</a>'."\n";
     } 
}
echo $html;
<br><font color="#e78608">------解决方案--------------------</font><br>睡不着觉,给你改一个吧,不是不会,估计你就是太懒。。。。。。。。。。<br><br>把数组中的{sl}换成{span}啦,要不还要取子串<br><br><dl class="code">PHP code<pre class="brush:php;toolbar:false">
<?php $videolist = "优酷{span}youku{span}地址1{span}地址2{span}地址3{li}土豆{span}tudou{span}土豆地址{li}新浪{span}sina{span}新浪地址1{span}新浪地址2{span}新浪地址3{li}";
?>
Copy after login
$value if(!empty($video[0])) { echo"" ; } //$url = $video[1]; } ?>
"; } ?>
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!