DolDurma
DolDurma

Reputation: 17303

PHP using itrator solution to find all tags match

You suppose i have this string:

$text= "11111111<mft:A>2222222</mft:A>1111111<mft:S>33333333</mft:S> 
        <mft:A>99999</mft:A><mft:S>v44444444/mft:S><mft:R>555555</mft:R>
        <mft:S>6666666</mft:S><mft:A>7777777</mft:A>111111";

i'm trying to find all texts are between this tag <mft:A> and </mft:A>

i know whats solution of this action on java but i don't know how can i implementing that on PHP and what's equvalent, for example:

String text= "11111111<mft:A>2222222</mft:A>1111111<mft:S>33333333</mft:S> 
        <mft:A>99999</mft:A><mft:S>v44444444/mft:S><mft:R>555555</mft:R>
        <mft:S>6666666</mft:S><mft:A>7777777</mft:A>111111";

Pattern mftA_REGEX = Pattern.compile("<mft:A>(.+?)</mft:A>");
Matcher matcher = mftA_REGEX.matcher(str);
if (matcher.find()) {
    String found = matcher.group(1);
}

Upvotes: 0

Views: 49

Answers (1)

Richard
Richard

Reputation: 628

Try it with this regex:

preg_match_all("/<mft:A>(.+?)<\/mft:A>/", $input_lines, $output_array);

OR

preg_match("/<mft:A>(.+?)<\/mft:A>/", $input_line, $output_array);

Upvotes: 2

Related Questions