从php中的字符串中提取子字符串

时间:2018-03-01 09:19:06

标签: php substring extract preg-match-all

也许是一个愚蠢的问题,但我已经在这上面浪费了很多时间....请帮助。下面是$ string变量中的字符串。它是一个HTML代码,我想从中提取特定的html代码,这是在代码底部给出的。 我的字符串如下:

<tbody>
      <tr class="odd views-row-first">
              <td class="views-field views-field-uri" >
        <a href="https://concen.org/sites/default/files/torrents/What%20Doctors%20Dont%20Tell%20You.2017.09.pdf_.torrent"><img src='https://concen.org/sites/default/modules/torrent/includes/images/icon_download3.gif'></a>          </td>
              <td class="views-field views-field-name-1" >
        <a class="magnetlink" href='?xt=urn:btih:0b256e3c43761efea517d966136c18d8e9c0a6d9&tr=http://concen.org:6969/announce&dn=What Doctors Dont Tell You.2017.09.pdf'><img src="https://concen.org/sites/default/modules/torrent/includes/images/icon-magnet.gif"></a>          </td>
              <td class="views-field views-field-title" >
        <a href="/content/what-doctors-dont-tell-you-september-2017">What Doctors Don't Tell You, September 2017</a>          </td>
              <td class="views-field views-field-name" >
        <span class="username" xml:lang="" about="/users/nibs" typeof="sioc:UserAccount" property="foaf:name" datatype="">nibs</span>          </td>
              <td class="views-field views-field-created active" >
        <em class="placeholder">5 months 2 weeks</em> ago          </td>
              <td class="views-field views-field-size" >
        12.58 MB          </td>
              <td class="views-field views-field-seeds" >
        8          </td>
              <td class="views-field views-field-peers" >
        0          </td>
              <td class="views-field views-field-raw-field" >
        258          </td>
          </tr>
      <tr class="even">
              <td class="views-field views-field-uri" >
        <a href="https://concen.org/sites/default/files/torrents/What.Doctors.Dont_.Tell_.You_.%20Jun2017.torrent"><img src='https://concen.org/sites/default/modules/torrent/includes/images/icon_download3.gif'></a>          </td>
              <td class="views-field views-field-name-1" >
        <a class="magnetlink" href='?xt=urn:btih:c8dfc582881cb58dcb41f74cf874b6ba5ac78572&tr=udp://concen.org:6969/announce&dn=What Doctors Don't Tell You - June 2017.pdf'><img src="https://concen.org/sites/default/modules/torrent/includes/images/icon-magnet.gif"></a>          </td>
              <td class="views-field views-field-title" >
        <a href="/content/what-doctors-dont-tell-you-june-2017">What Doctors Don't Tell You, June 2017</a>          </td>
              <td class="views-field views-field-name" >
        <span class="username" xml:lang="" about="/users/nibs" typeof="sioc:UserAccount" property="foaf:name" datatype="">nibs</span>          </td>
              <td class="views-field views-field-created active" >
        <em class="placeholder">8 months 2 weeks</em> ago          </td>
              <td class="views-field views-field-size" >
        16.06 MB          </td>
              <td class="views-field views-field-seeds" >
        2          </td>
              <td class="views-field views-field-peers" >
        0          </td>
              <td class="views-field views-field-raw-field" >
        265          </td>
          </tr>
      <tr class="odd">
              <td class="views-field views-field-uri" >
        <a href="https://concen.org/sites/default/files/torrents/Gerard%20S.%20Doyle%20-%20When%20There%20Is%20No%20Doctor%20-%20Preventive%20and%20Emergency%20Healthcare%20in%20Challenging%20Times%20-%20epub%20%5BTKRG%5D.torrent"><img src='https://concen.org/sites/default/modules/torrent/includes/images/icon_download3.gif'></a>          </td>
              <td class="views-field views-field-name-1" >
        <a class="magnetlink" href='?xt=urn:btih:1d225bc1c5fd947cb5c2573af25960fbbd545ebb&tr=udp://tracker.opentrackr.org:1337/announce&dn=Gerard S. Doyle - When There Is No Doctor - Preventive and Emergency Healthcare in Challenging Times - epub [TKRG]'><img src="https://concen.org/sites/default/modules/torrent/includes/images/icon-magnet.gif"></a>          </td>
              <td class="views-field views-field-title" >
        <a href="/content/gerard-s-doyle-when-there-no-doctor-preventive-and-emergency-healthcare-challenging-times">Gerard S. Doyle - When There Is No Doctor -...</a>          </td>
              <td class="views-field views-field-name" >
        <span class="username" xml:lang="" about="/users/roflcopter2110" typeof="sioc:UserAccount" property="foaf:name" datatype="">roflcopter2110</span>          </td>
              <td class="views-field views-field-created active" >
        <em class="placeholder">10 months 2 weeks</em> ago          </td>
              <td class="views-field views-field-size" >
        1 MB          </td>
              <td class="views-field views-field-seeds" >
        28          </td>
              <td class="views-field views-field-peers" >
        3          </td>
              <td class="views-field views-field-raw-field" >
        1314          </td>
          </tr>
      <tr class="even">
              <td class="views-field views-field-uri" >
        <a href="https://concen.org/sites/default/files/torrents/Demonoid_www.DNOID_.me-_What_Doctors_Dont_Tell_You_April_2017_True_PDF_4664_%5BECLiPSE%5D.torrent"><img src='https://concen.org/sites/default/modules/torrent/includes/images/icon_download3.gif'></a>          </td>
              <td class="views-field views-field-name-1" >
        <a class="magnetlink" href='?xt=urn:btih:3f6d183ea4cfc87b447b10a1dde0f25105296918&tr=udp://tracker.coppersurfer.tk:6969/announce&dn=What Doctors Dont Tell You - April 2017 - True PDF - 4664 [ECLiPSE]'><img src="https://concen.org/sites/default/modules/torrent/includes/images/icon-magnet.gif"></a>          </td>
              <td class="views-field views-field-title" >
        <a href="/content/what-doctors-dont-tell-you-april-2017-true-pdf-4664-eclipse">What Doctors Dont Tell You - April 2017 - True...</a>          </td>
              <td class="views-field views-field-name" >
        <span class="username" xml:lang="" about="/users/nibs" typeof="sioc:UserAccount" property="foaf:name" datatype="">nibs</span>          </td>
              <td class="views-field views-field-created active" >
        <em class="placeholder">11 months 3 days</em> ago          </td>
              <td class="views-field views-field-size" >
        34.36 MB          </td>
              <td class="views-field views-field-seeds" >
        44          </td>
              <td class="views-field views-field-peers" >
        5          </td>
              <td class="views-field views-field-raw-field" >
        2678          </td>
          </tr>
      <tr class="odd views-row-last">
              <td class="views-field views-field-uri" >
        <a href="https://concen.org/sites/default/files/torrents/5063.torrent"><img src='https://concen.org/sites/default/modules/torrent/includes/images/icon_download3.gif'></a>          </td>
              <td class="views-field views-field-name-1" >
        <a class="magnetlink" href='?xt=urn:btih:68b73463431f686800ccf97a1c53985c568e922a&tr=http://concen.org:6969/announce&dn=Doctor Yourself - Natural Healing That Works.mp3'><img src="https://concen.org/sites/default/modules/torrent/includes/images/icon-magnet.gif"></a>          </td>
              <td class="views-field views-field-title" >
        <a href="/content/doctor-yourself-natural-healing-works">Doctor Yourself - Natural Healing That Works</a>          </td>
              <td class="views-field views-field-name" >
        <span class="username" xml:lang="" about="/users/concen" typeof="sioc:UserAccount" property="foaf:name" datatype="">ConCen</span>          </td>
              <td class="views-field views-field-created active" >
        <em class="placeholder">9 years 1 month</em> ago          </td>
              <td class="views-field views-field-size" >
        546.75 MB          </td>
              <td class="views-field views-field-seeds" >
        3          </td>
              <td class="views-field views-field-peers" >
        0          </td>
              <td class="views-field views-field-raw-field" >
        20          </td>
          </tr>
  </tbody>

我希望提取每次出现的

 <td class="views-field views-field-uri"> (.*?) </td>

in

 content[0],content[1],content[2] and so on....

0 个答案:

没有答案