Maison développement back-end tutoriel php 多次explode切割并组合,应该如何做呢

多次explode切割并组合,应该如何做呢

Jun 13, 2016 pm 12:13 PM
gt html lt nbsp

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

本帖最后由 lovepzt 于 2015-01-09 19:16:09 编辑
引用
$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

  • 第一集
    第二集
    第三集
    第四集
    第五集
    ------解决思路----------------------

    1

    $a = explode('$$$', $a);<br />$b = explode('$$$', $b);<br />foreach($a as $i=>$r) {<br />  echo "<li>$r</li>\n";<br />  foreach(explode("\n", $b[$i]) as $j=>$v) {<br />    $t = explode('$', trim($v));<br />    printf("<a href='%d_%d.html' target='_top'>%s</a>\n", $i+1, $j+1, $t[0]);<br />  }<br />}

    Copier après la connexion

    1

    <li>youku</li><br /><a href='1_1.html' target='_top'>第一集</a><br /><a href='1_2.html' target='_top'>第一集</a><br /><a href='1_3.html' target='_top'>第二集</a><br /><a href='1_4.html' target='_top'>第三集</a><br /><a href='1_5.html' target='_top'>第四集</a><br /><a href='1_6.html' target='_top'>第五集</a><br /><li>tudou</li><br /><a href='2_1.html' target='_top'>第一集</a><br /><a href='2_2.html' target='_top'>第一集</a><br /><a href='2_3.html' target='_top'>第二集</a><br /><a href='2_4.html' target='_top'>第三集</a><br /><a href='2_5.html' target='_top'>第四集</a><br /><a href='2_6.html' target='_top'>第五集</a><br /><li>down</li><br /><a href='3_1.html' target='_top'>第一集</a><br /><a href='3_2.html' target='_top'>第一集</a><br /><a href='3_3.html' target='_top'>第二集</a><br /><a href='3_4.html' target='_top'>第三集</a><br /><a href='3_5.html' target='_top'>第四集</a><br /><a href='3_6.html' target='_top'>第五集</a><br />

    Copier après la connexion


    但你的数据本该是这样的

    1

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

    Copier après la connexion

    1

    <li>youku</li><br /><a href='1_1.html' target='_top'>第一集</a><br /><a href='1_2.html' target='_top'>第二集</a><br /><a href='1_3.html' target='_top'>第三集</a><br /><a href='1_3.html' target='_top'>第四集</a><br /><a href='1_5.html' target='_top'>第五集</a><br /><li>tudou</li><br /><a href='2_1.html' target='_top'>第一集</a><br /><a href='2_2.html' target='_top'>第二集</a><br /><a href='2_3.html' target='_top'>第三集</a><br /><a href='2_4.html' target='_top'>第四集</a><br /><a href='2_5.html' target='_top'>第五集</a><br /><li>down</li><br /><a href='3_1.html' target='_top'>第一集</a><br /><a href='3_2.html' target='_top'>第二集</a><br /><a href='3_3.html' target='_top'>第三集</a><br /><a href='3_4.html' target='_top'>第四集</a><br /><a href='3_5.html' target='_top'>第五集</a><br /><br />

    Copier après la connexion
    Déclaration de ce site Web
    Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn

    Article chaud

    Musée de deux points: Guide de localisation de Bungle Wasteland
    4 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
    Combien de temps faut-il pour battre Split Fiction?
    3 Il y a quelques semaines By DDD
    Repo: Comment relancer ses coéquipiers
    3 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
    Hello Kitty Island Adventure: Comment obtenir des graines géantes
    3 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌

    Article chaud

    Musée de deux points: Guide de localisation de Bungle Wasteland
    4 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
    Combien de temps faut-il pour battre Split Fiction?
    3 Il y a quelques semaines By DDD
    Repo: Comment relancer ses coéquipiers
    3 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
    Hello Kitty Island Adventure: Comment obtenir des graines géantes
    3 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌

    Tags d'article chaud

    Bloc-notes++7.3.1

    Bloc-notes++7.3.1

    Éditeur de code facile à utiliser et gratuit

    SublimeText3 version chinoise

    SublimeText3 version chinoise

    Version chinoise, très simple à utiliser

    Envoyer Studio 13.0.1

    Envoyer Studio 13.0.1

    Puissant environnement de développement intégré PHP

    Dreamweaver CS6

    Dreamweaver CS6

    Outils de développement Web visuel

    SublimeText3 version Mac

    SublimeText3 version Mac

    Logiciel d'édition de code au niveau de Dieu (SublimeText3)

    Tableau imbriqué en HTML Tableau imbriqué en HTML Sep 04, 2024 pm 04:49 PM

    Tableau imbriqué en HTML

    Bordure de tableau en HTML Bordure de tableau en HTML Sep 04, 2024 pm 04:49 PM

    Bordure de tableau en HTML

    Marge gauche HTML Marge gauche HTML Sep 04, 2024 pm 04:48 PM

    Marge gauche HTML

    Disposition du tableau HTML Disposition du tableau HTML Sep 04, 2024 pm 04:54 PM

    Disposition du tableau HTML

    Déplacer du texte en HTML Déplacer du texte en HTML Sep 04, 2024 pm 04:45 PM

    Déplacer du texte en HTML

    Liste ordonnée HTML Liste ordonnée HTML Sep 04, 2024 pm 04:43 PM

    Liste ordonnée HTML

    Bouton HTML onclick Bouton HTML onclick Sep 04, 2024 pm 04:49 PM

    Bouton HTML onclick

    Comment analysez-vous et traitez-vous HTML / XML dans PHP? Comment analysez-vous et traitez-vous HTML / XML dans PHP? Feb 07, 2025 am 11:57 AM

    Comment analysez-vous et traitez-vous HTML / XML dans PHP?

    See all articles