0

i have one array and i want to fill from 2 foreach

preg_match_all('/<div[^>]+class="titr2"[^>]*>\s*<a[^>]+>(.*?)<\/a>\s*<\/div>/si', file_get_contents($handle), $names);


$other = array();

foreach ($names[0] as $value) {

    $pattern = '/<a[^>]*>(.*?)<\/a>/si';
    preg_match($pattern, $value, $matches);

    $name['A'] = $matches[1];
    $other[]   = $name;
}

preg_match_all('/<\/a><\/div>(.*?)\s*<div[^>]+class="toolz"[^>]*>\s*/si',   file_get_contents($handle), $other);
foreach ($other[1] as $value) {

    $default = preg_replace('/<img[^>]*>(.*)\/>/is', "", $value);
    $default = explode('<br />', $default);

    $name['B'] = $default[0];
    $name['C'] = $default[1];
    $other[]=$name;
}
echo"<pre>";print($other);echo"</pre>";

i want to have like this Result :

$other = array
(
    0 => array
        (
            'A' => 'aaaaaaaaaaaa',
            'B' => 'bbbbbbbbbbbb',
            'C' => 'cccccccccccc'
        ),
    1 => array
        (
            'A' => 'dddddddddddd',
            'B' => 'eeeeeeeeeeee',
            'C' => 'ffffffffffff'
        ),
    2 => array
        (
            'A' => 'gggggggggggg',
            'B' => 'hhhhhhhhhhhh',
            'C' => 'iiiiiiiiiiii'
        )                
);

UPDATED:

Current Result:

5
  • 1
    What is the current result? Would help if you can add a sample of the file you're working with. Commented Feb 8, 2014 at 9:45
  • @AmalMurali this fill bad array with no need rows Commented Feb 8, 2014 at 9:48
  • That doesn't quite answer the question of what exact results you'Re getting ;) Please just show a var_dump() of what you currently get. Commented Feb 8, 2014 at 9:53
  • @JohannesH. i'm edited post and paste result of that on paste.debian.net Commented Feb 8, 2014 at 9:55
  • That... unicode... stuff... Oo Commented Feb 8, 2014 at 10:08

1 Answer 1

2
preg_match_all('/<div[^>]+class="titr2"[^>]*>\s*<a[^>]+>(.*?)<\/a>\s*<\/div>/si',  file_get_contents($handle), $names);


$result = array('A'=>array(), 'B'=>array(), 'C'=>array());

foreach ($names[0] as $value) {

    $pattern = '/<a[^>]*>(.*?)<\/a>/si';
    preg_match($pattern, $value, $matches);
    foreach ($matches[1] as $match){
        $result['A'][]   = $match;
    }
}

preg_match_all('/<\/a><\/div>(.*?)\s*<div[^>]+class="toolz"[^>]*>\s*/si',   file_get_contents($handle), $other);
foreach ($other[1] as $value) {

    $default = preg_replace('/<img[^>]*>(.*)\/>/is', "", $value);
    $default = explode('<br />', $default);

    $result['B'][] = $default[0];
    $result['C'][] = $default[1];
}
echo"<pre>";print($result);echo"</pre>";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.