Rumah > Artikel > pembangunan bahagian belakang > PHP如何将数组的内容循环成 “链接”+“下拉选择”的样式
PHP怎么将数组的内容循环成 “链接”+“下拉选择”的样式
自己写的一个循环:
<!-- 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; ?>
<!-- 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>
<!-- 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>
$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}"; ?>