Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Help me please :)

Last post 07-08-2008, 9:46 AM by ddrudik. 3 replies.
Sort Posts: Previous Next
  •  07-08-2008, 5:30 AM 43856

    Help me please :)

    I need to create regular expression for:

    <span class="myClass">some text 1</span>
    some text under 1
    <span class="myClass">some text 2</span>
    some text under 2
    <span class="myClass">some text 3</span>
    some text under 3


    How i can get into array all text 

    some text n

    and

     some text under n

    using preg_match_all

    class of span is knowing

    tnx

     

  •  07-08-2008, 7:03 AM 43860 in reply to 43856

    Re: Help me please :)

    Based on your sample:

    Raw Match Pattern:
    <span class="myClass">(.*?)</span>\r\n(.*?)(?:\r|$)

    
    PHP Code Example:
    <?php
    $sourcestring="your source string";
    preg_match_all('#<span class="myClass">(.*?)</span>\r\n(.*?)(?:\r|$)#',$sourcestring,$matches);
    echo "<pre>".print_r($matches,true);
    ?>
    


    $matches Array:
    (
        [0] => Array
            (
                [0] => <span class="myClass">some text 1</span>
    some text under 1
                [1] => <span class="myClass">some text 2</span>
    some text under 2
                [2] => <span class="myClass">some text 3</span>
    some text under 3
            )

        [1] => Array
            (
                [0] => some text 1
                [1] => some text 2
                [2] => some text 3
            )

        [2] => Array
            (
                [0] => some text under 1
                [1] => some text under 2
                [2] => some text under 3
            )

    )


  •  07-08-2008, 9:02 AM 43869 in reply to 43860

    Re: Help me please :)

    Soory, but it isn`t work if:

    1. \r\n not exists in text

    2. if  another HTML tags exists in  "some text under n"

     

    <span class="xpert">some text 1. </span></p><p>some text under 1<br><span class="xpert">....
    it may looks like this :( 
  •  07-08-2008, 9:46 AM 43875 in reply to 43869

    Re: Help me please :)

    If you require a working solution for your actual text then we need to see your actual text.
View as RSS news feed in XML