【问题标题】:how do I split with preg_split in php my lines?如何在 php 中使用 preg_split 拆分我的行?
【发布时间】:2015-05-07 14:41:17
【问题描述】:

我有以下文字

        <h2>Subjects</h2>
        <ul>

        <li><a href='http://isbndb.com/subject/transfer_pricing'>
        Transfer pricing</a></li>

        <li><a   
        hef='http://isbndb.com/subject/intangible_property_valuation'>   
        Intangible property -- Valuation</a></li>


        </ul>

&lt;li&gt; .. &lt;/li&gt; 的数量可能是可变的。 谁能告诉我获取的正则表达式

     Transfer pricing
     Intangible property -- Valuation

它可以用 preg_split 完成,但我不知道正则表达式应该如何。 非常感谢。

【问题讨论】:

  • 你不应该使用正则表达式来解析 html,你会遇到很多挑战。考虑改用\DomDocument
  • @Augwa 你有这方面的更多信息吗?
  • 这里的问题将为您解答所有问题stackoverflow.com/questions/1732348/…
  • 非常感谢!恭喜

标签: php regex preg-split


【解决方案1】:

试试这样的:

   $output = "<h2>Subjects</h2>
    <ul>

    <li><a href='http://isbndb.com/subject/transfer_pricing'>
    Transfer pricing</a></li>

    <li><a   
    hef='http://isbndb.com/subject/intangible_property_valuation'>   
    Intangible property -- Valuation</a></li>


    </ul>";

   preg_match_all("li><a href='(.[^>]*)>(.[^<]*)</",$output , $array_check);


        print_r($array_check);

【讨论】:

    猜你喜欢
    • 2011-06-11
    • 2013-04-30
    • 2019-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多