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

 

Link to comment
Share on other sites

<?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
)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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