Jump to content

[SOLVED] Matching (123) (51) parentheses and a bit html ?


chrisran

Recommended Posts

Hi,

 

I'm again trying to match against html, but it works only partly.

 

$string = "<option title='(71) (1)'>Phase71 Cluster1</option><option title='(49) (1)'>Phase49 Cluster1</option><option title='(36) (1)'>Phase36 Cluster1</option>";

 

What I've tried:

$getteklistexp = "/title='\(.*?\)[^>]*\(.*?\)'>.*?<\/option><option/";

 

I cant use "<option title" because sometimes I have a id=xyz in between, therefore I try to grep on title=' and then I'd like to have an array like this:

 

[0] = 71

[1] = 1

[2] = Phase71 Cluster1

[3] = 49

[4] = 1

[5] = Phase49 Cluster1

...

 

My result is:

[0] => title='(71) (1)'>Phase1 Cluster1

 

What am I missing this time ? :)

 

Thanks

 

<?php
$string = "<option title='(71) (1)'>Phase71 Cluster1</option><option title='(49) (1)'>Phase49 Cluster1</option><option title='(36) (1)'>Phase36 Cluster1</option>";
preg_match_all("~title='\(([0-9]+)\) \(([0-9]+)\)'>([^<]+)<~i", $string, $matches, PREG_SET_ORDER);
//put all captured matches in a single-dimension array
$singledim = array();
foreach ($matches as $arr) {
array_shift($arr);
$singledim = array_merge($singledim, $arr);
}
echo '<pre>' . print_r($singledim, true) . '</pre>';
?>

 

Output:

Array
(
    [0] => 71
    [1] => 1
    [2] => Phase71 Cluster1
    [3] => 49
    [4] => 1
    [5] => Phase49 Cluster1
    [6] => 36
    [7] => 1
    [8] => Phase36 Cluster1
)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.