如何在php中使用preg_split分割我的行?

时间:2022-08-07 21:39:01

I have following text

我有以下文字

        <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>

the numbers of <li> .. </li> could be variable. Can anyone tell me the regex to get

  • .. 的数量可以是变量。谁能告诉我正则表达式

  •      Transfer pricing
         Intangible property -- Valuation
    

    it might be done with preg_split, but I have no glue how the regex should be. Thanks a lot.

    它可能是用preg_split完成的,但是我没有胶水应该如何正则表达式。非常感谢。

    1 个解决方案

    #1


    Try some thing like this:

    尝试这样的事情:

       $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);
    

    #1


    Try some thing like this:

    尝试这样的事情:

       $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);