Jump to content

Boozi

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Boozi's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi all, Long time reader, first time poster... I've hit a wall trying to get this working : I'm trying to extract sets of fields from a non-static file. The fields inside this file are defined like this : [code] [[fieldname]]content of field.[[/fieldname]] [/code] Opening/closing tags & content can be spread across multiple lines like so: [code] [[field1]]content1[[/field1]] [[field2]] content2 [[/field2]] [[field3]] line1 line2 line3 [[/field3]] [/code] This is what I have so far: [code] preg_match_all( '/\[\[([a-z0-9]+)\]\](.*)\[\[\/([a-z0-9]+)\]\]/si' , $filestring , $fields , PREG_SET_ORDER ); [/code] The resulting $fields contains this : (spaces added for extra readability) [code]     [0] => Array         (             [0] => [[field1]]content1[[/field1]]                       [[field2]]                       content2                       [[/field2]]                       [[field3]]                       line1                       line2                       line3                       [[/field3]]             [1] => field1             [2] => content1[[/field1]]                       [[field2]]                       content2                       [[/field2]]                       [[field3]]                       line1                       line2                       line3             [3] => field3         ) [/code] It seems that preg_match_all "skips" [[/field1]] and [[/field2]], am I overlooking something obvious? The result I'm looking for is this : (spaces added for extra readability) [code]     [0] => Array         (             [0] => [[field1]]content1[[/field1]]             [1] => field1             [2] => content1             [3] => field1         )     [1] => Array         (             [0] => [[field2]]                       content2                       [[/field2]]             [1] => field2             [2] => content2             [3] => field2         )     [2] => Array         (             [0] => [[field3]]                       line1                       line2                       line3                       [[/field3]]             [1] => field3             [2] => line1                       line2                       line3             [3] => field3         ) [/code] Any ideas or solutions would be much appreciated!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.