foreach ($payload->commits as $commit) { // Check the commit message for card references. Should be full URLs to card or the share URL. $msg = $commit->message; $cards = array(); while (stristr($msg, $find)) { $msg = substr($msg, strpos($msg, $find)); $a = explode($find, $msg); $i = empty($a[0]) ? 1 : 0; // index of a to use if (strstr($a[$i], "/")) { $c = explode("/", $a[$i]); $cards[] = $c[0]; $msg = substr($msg, strpos($msg, $c[0])); } else { if (strstr($a[$i], " ")) { $c = explode(" ", $a[$i]); $cards[] = $c[0]; $msg = substr($msg, strpos($msg, $c[0])); } } } if (count($cards) > 1) { $total_commits_used++; $comment = "Commit {$commit->id} by {$commit->author->name}\n------\n{$commit->message}\n------\n{$commit->url}"; foreach ($cards as $card) { $trello->post("cards/{$card}/actions/comments", array("text" => $comment)); $total_cards_used++; } } } die("Updated {$total_cards_used} from {$total_commits_used} commits.");