多次explode切割并组合,应该怎么做呢

WBOY
Release: 2016-06-23 13:41:53
Original
1385 people have browsed it

$a='youku$$$tudou$$$down'
$b='第一集$abcd
第一集$abcd
第二集$abcd
第三集$abcd
第四集$abcd
第五集$abcd$$$第一集$abcd
第一集$abcd
第二集$abcd
第三集$abcd
第四集$abcd
第五集$abcd$$$第一集$abcd
第一集$abcd
第二集$abcd
第三集$abcd
第四集$abcd
第五集$abcd'



都是$$$分割对应
最后$或者换行分割
最后需要得到
  • youku

  • 第一集
    第二集
    第三集
    第四集
    第五集

  • tudou

  • 第一集
    第二集
    第三集
    第四集
    第五集

  • down

  • 第一集
    第二集
    第三集
    第四集
    第五集


    回复讨论(解决方案)

    $a = 'youku$$$tudou$$$down';$b='第一集$abcd第一集$abcd第二集$abcd第三集$abcd第四集$abcd第五集$abcd$$$第一集$abcd第一集$abcd第二集$abcd第三集$abcd第四集$abcd第五集$abcd$$$第一集$abcd第一集$abcd第二集$abcd第三集$abcd第四集$abcd第五集$abcd';$a = explode('$$$', $a);$b = explode('$$$', $b);foreach($a as $i=>$r) {  echo "<li>$r</li>\n";  foreach(explode("\n", $b[$i]) as $v) {    $t = explode('$', trim($v));    echo "<a href='$t[1]' target='_top'>$t[0]</a>\n";  }}
    Copy after login
    Copy after login
    <li>youku</li><a href='abcd' target='_top'>第一集</a><a href='abcd' target='_top'>第一集</a><a href='abcd' target='_top'>第二集</a><a href='abcd' target='_top'>第三集</a><a href='abcd' target='_top'>第四集</a><a href='abcd' target='_top'>第五集</a><li>tudou</li><a href='abcd' target='_top'>第一集</a><a href='abcd' target='_top'>第一集</a><a href='abcd' target='_top'>第二集</a><a href='abcd' target='_top'>第三集</a><a href='abcd' target='_top'>第四集</a><a href='abcd' target='_top'>第五集</a><li>down</li><a href='abcd' target='_top'>第一集</a><a href='abcd' target='_top'>第一集</a><a href='abcd' target='_top'>第二集</a><a href='abcd' target='_top'>第三集</a><a href='abcd' target='_top'>第四集</a><a href='abcd' target='_top'>第五集</a>
    Copy after login
    Copy after login

    超链接输出错误了

    $a = 'youku$$$tudou$$$down';$b='第一集$abcd第一集$abcd第二集$abcd第三集$abcd第四集$abcd第五集$abcd$$$第一集$abcd第一集$abcd第二集$abcd第三集$abcd第四集$abcd第五集$abcd$$$第一集$abcd第一集$abcd第二集$abcd第三集$abcd第四集$abcd第五集$abcd';$a = explode('$$$', $a);$b = explode('$$$', $b);foreach($a as $i=>$r) {  echo "<li>$r</li>\n";  foreach(explode("\n", $b[$i]) as $v) {    $t = explode('$', trim($v));    echo "<a href='$t[1]' target='_top'>$t[0]</a>\n";  }}
    Copy after login
    Copy after login
    <li>youku</li><a href='abcd' target='_top'>第一集</a><a href='abcd' target='_top'>第一集</a><a href='abcd' target='_top'>第二集</a><a href='abcd' target='_top'>第三集</a><a href='abcd' target='_top'>第四集</a><a href='abcd' target='_top'>第五集</a><li>tudou</li><a href='abcd' target='_top'>第一集</a><a href='abcd' target='_top'>第一集</a><a href='abcd' target='_top'>第二集</a><a href='abcd' target='_top'>第三集</a><a href='abcd' target='_top'>第四集</a><a href='abcd' target='_top'>第五集</a><li>down</li><a href='abcd' target='_top'>第一集</a><a href='abcd' target='_top'>第一集</a><a href='abcd' target='_top'>第二集</a><a href='abcd' target='_top'>第三集</a><a href='abcd' target='_top'>第四集</a><a href='abcd' target='_top'>第五集</a>
    Copy after login
    Copy after login

    错了?哪里错了?
    我总不能无中生有吧?

    超链接应该是
    youku
    1_1.html
    1_2.html
    1_3.html
    ``````````

    tudou
    2_1.html
    2_2.html
    2_3.html
    ```````````

    down
    3_1.html
    3_2.html
    3_3.html
    `````````

    多个循环输出真不知道要怎么搞

    错了?哪里错了?
    我总不能无中生有吧?

    页面应是真实存在的,应填写在你数据的 abcd 位置
    动态生成的怎么能和真实页面对应起来?

    *_*.html
    (这里是youku tudou down第次的数组)_(这里是各组又重新对应的ID).html

    改成这样的话,就链接名称错了,超链接的数组能不能从1开始算起,不从0算起?


    $a = 'youku$$$tudou$$$down';$b='第一集$abcd第一集$abcd第二集$abcd第三集$abcd第四集$abcd第五集$abcd$$$第六集$abcd第七集$abcd第八集$ddddd第九集$abcd第十集$abcd第十一集$abcd$$$第十二集$abcd第十三集$abcd第十四集$abcd第十五集$abcd第十六集$abcd第十七集$efghijk';$a = explode('$$$', $a);$b = explode('$$$', $b);foreach($a as $i=>$r) {  echo "<li>$r</li>\n";  foreach(explode("\n", $b[$i]) as $v=>$lala) {    $t = explode('$', trim($v));    echo "<a href='".$i."_".$t[0].".html' target='_top'>$t[0]</a>\n";  }}
    Copy after login




    页面应是真实存在的,应填写在你数据的 abcd 位置
    动态生成的怎么能和真实页面对应起来?

    $a = explode('$$$', $a);$b = explode('$$$', $b);foreach($a as $i=>$r) {  echo "<li>$r</li>\n";  foreach(explode("\n", $b[$i]) as $j=>$v) {    $t = explode('$', trim($v));    printf("<a href='%d_%d.html' target='_top'>%s</a>\n", $i+1, $j+1, $t[0]);  }}
    Copy after login
    <li>youku</li><a href='1_1.html' target='_top'>第一集</a><a href='1_2.html' target='_top'>第一集</a><a href='1_3.html' target='_top'>第二集</a><a href='1_4.html' target='_top'>第三集</a><a href='1_5.html' target='_top'>第四集</a><a href='1_6.html' target='_top'>第五集</a><li>tudou</li><a href='2_1.html' target='_top'>第一集</a><a href='2_2.html' target='_top'>第一集</a><a href='2_3.html' target='_top'>第二集</a><a href='2_4.html' target='_top'>第三集</a><a href='2_5.html' target='_top'>第四集</a><a href='2_6.html' target='_top'>第五集</a><li>down</li><a href='3_1.html' target='_top'>第一集</a><a href='3_2.html' target='_top'>第一集</a><a href='3_3.html' target='_top'>第二集</a><a href='3_4.html' target='_top'>第三集</a><a href='3_5.html' target='_top'>第四集</a><a href='3_6.html' target='_top'>第五集</a>
    Copy after login


    但你的数据本该是这样的
    $a = 'youku$$$tudou$$$down';$b='第一集$1_1.html第二集$1_2.html第三集$1_3.html第四集$1_3.html第五集$1_5.html$$$第一集$2_1.html第二集$2_2.html第三集$2_3.html第四集$2_4.html第五集$2_5.html$$$第一集$3_1.html第二集$3_2.html第三集$3_3.html第四集$3_4.html第五集$3_5.html'; $a = explode('$$$', $a);$b = explode('$$$', $b);foreach($a as $i=>$r) {  echo "<li>$r</li>\n";  foreach(explode("\n", $b[$i]) as $v) {    $t = explode('$', trim($v));    echo "<a href='$t[1]' target='_top'>$t[0]</a>\n";  }}
    Copy after login
    <li>youku</li><a href='1_1.html' target='_top'>第一集</a><a href='1_2.html' target='_top'>第二集</a><a href='1_3.html' target='_top'>第三集</a><a href='1_3.html' target='_top'>第四集</a><a href='1_5.html' target='_top'>第五集</a><li>tudou</li><a href='2_1.html' target='_top'>第一集</a><a href='2_2.html' target='_top'>第二集</a><a href='2_3.html' target='_top'>第三集</a><a href='2_4.html' target='_top'>第四集</a><a href='2_5.html' target='_top'>第五集</a><li>down</li><a href='3_1.html' target='_top'>第一集</a><a href='3_2.html' target='_top'>第二集</a><a href='3_3.html' target='_top'>第三集</a><a href='3_4.html' target='_top'>第四集</a><a href='3_5.html' target='_top'>第五集</a>
    Copy after login

    非常感谢

    其实这就一个播放地址,abcd是播放地址,要另做它用

    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!