0

I need to iterate through an array, and edit each value but not differently.

<?php
Function parseStatus($Input, $Start, $End){
    $String = " " . $Input;
    $Init = StrPos($String, $Start);

    If($Init == 0){
        Return '';
    }

    $Init += StrLen($Start);
    $Length = StrPos($String, $End, $Init) - $Init;

    Return SubStr($String, $Init, $Length);
}

Function getAllStatuses($Username){
    $DOM = new DOMDocument();
    $DOM->validateOnParse = True;
    @$DOM->loadHtml(File_Get_Contents('http://lifestream.aol.com/stream/' . $Username));
    $xPath = new DOMXPath($DOM);

    $Stream = $DOM->getElementById('stream')->nodeValue; // return stream content for display name
    $Nodes = $xPath->query('//div[@class="stream"]');

    $Name = Explode(' ', Trim($Stream));
    $User = $Name[0];

    $Statuses = Array();

    ForEach($Nodes as $Node){
        ForEach($Node->getElementsByTagName('li') as $Key => $Tags){
            $Statuses[] = $Tags->nodeValue;
        }
    }

    ForEach($Statuses as $Status){
        If(StrPos($Status, 'Services')){
            Echo 'services is definitely in there';
            $New = AIM::parseStatus($Status, $User, 'Services');
            Echo $New;
            Break;
        }
    }
?>

The issue is, $New only echos the very first output, but how do I get that to run through each value in the array, and do the same thing?

Expected output: [name as start] what i need [word Services]

Then on each value in the array, do the same thing so it'd be like:

what i need

again what i need but different string

etc.

Thanks for any help.

2
  • 1
    remove the Break; from it.. Commented Dec 11, 2013 at 3:50
  • ... I just shook my head at that LOL... Thanks again, I'm sorry smh Commented Dec 11, 2013 at 3:51

1 Answer 1

2

The Break; in your foreach loop is, well, breaking the loop.

Remove the Break; and it should work.

Have a read here:
http://www.php.net/break

break ends execution of the current for, foreach, while, do-while or switch structure.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks to Hardy I realized that, I was overthinking this one.

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.