php - Assign regex pattern as key to an array -


I have an array of regular expressions and trying to loop through a text document to find the first pattern Let's find the key for an array, then continue by finding another pattern and assigning it as value. Whenever I came in Pattern 1, I should always be assigned as a key and all patterns should follow 2 matches, unless I can not find a new key for the first key as values to be specified.

Text Document Structure:

  Topic: Email after some time: someemail@email.com Source: www.google.com www.stackoverflow.com www.reddit.com  

Then I have an array of expressions:

  $ expressions = array ('email' = & gt; '(\ b [a-zA] -Z0-9 ._% + -] + @ [a -ZA-Z0-9 .-] + \. [A-zA-Z] {2,4} \ b) ',' url '= & gt; '([A-Za-z] [A-Za-z0].!! -9 + .-] {1,120}: [one-zA-Z0-9 /] (([[za- _ + *,; /: @ & Amp; ~ = -]) |% [A-FA f0-9] {2}) {1,333} (# ([one-zA-Z0-9] [one-zA- Z0-9 $ _ + *,; /:.!? @ & Amp; ~ =% -] {0,1000})))) ');  

I want to loop through my text document and match the email address so that all URLs indexed as values ​​in the form of the key of the array, for the above text The output will be:

  array ('someemail@email.com' = & gt; array (0 = & gt; 'www.google.com', 1 = & gt; 'www.stackoverflow .com ', 2 = & gt;' www.reddit.com ')  

One way $ Note = $ parts [

preg_split ("/ (emailexpr) /", $ txt, -1, PREG_SPLIT_DELIM_CAPTURE); $ res = array (); // Notes: 0] ($ i = 1; isset ($ parts [$ i]); $ i + = 2) {$ ime = $ Parts [$ i]; $ chuck = $ parts [$] will be everything before the first amile expo match I + 1; if (preg_match_all ("/ domainexpr /", $ chuck, $ match)) $ $ [[Email] = $ match [0];}}

Change EmmilxP and DomxXP with your respex gabberish. / P>


Comments

Popular posts from this blog

paypal - How to know the URL referrer in PHP? -

oauth - Facebook OAuth2 Logout does not remove fb_ cookie -

wpf - Line breaks and indenting for the XAML of a saved FlowDocument? -