Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Difficulty with PHP regex

    I'm having real difficulty getting a PHP regex working and need some help! I have pages containing text in the following format:

    Code:
    Text
    <gallery>
    filename1|description1
    filename2|description2
    filename3|description3
    </gallery>
    More text
    I'm trying to create a regex which will match the entire text within the gallery tags, but I seem to be coming across a problem due to the carriage returns involved. My current expression is <*.+gallery> which returns only the tags themselves (and not the contents), and the contents aren't matched unless I change the text's format to:

    Code:
    Text
    <gallery>filename1|description1filename2|description2filename3|description3</gallery>
    More text
    Any suggestions on what I could add or change to make this work as desired with multi-line text?

  • #2
    New Coder
    Join Date
    Mar 2009
    Posts
    89
    Thanks
    5
    Thanked 14 Times in 14 Posts
    Hi, try something like this

    PHP Code:
    $s='Text
    <gallery>
    filename1|description1
    filename2|description2
    filename3|description3
    </gallery>
    More text'
    ;
    $arr = array();
    preg_match_all('#(?<=\<gallery\>)(.*)?(?:\</gallery\>)#misux',$s,&$arr);
    print_r($arr); 
    URL2SEO URL shortener and redirection services


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •