PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php function parseName(string $name): string { $initData = json_decode('{"id": 4795538598, "kind": "W2", "name": "{t2}", "match": {"id": 99966, "date": "2023-08-03T01:00:00.000000Z", "info": "", "name": "Stefanos Tsitsipas - John Isner", "sport": {"id": 5, "name": "sport.tennis", "created_at": "2023-06-21T10:39:01.000000Z", "live_delay": 0, "updated_at": "2023-06-21T10:39:01.000000Z"}, "stats": {"id": 22762465, "match": {"id": 99966, "date": "2023-08-03T01:00:00.000000Z", "info": "", "name": "Stefanos Tsitsipas - John Isner", "sport": {"id": 5, "name": "sport.tennis", "created_at": "2023-06-21T10:39:01.000000Z", "live_delay": 0, "updated_at": "2023-06-21T10:39:01.000000Z"}, "is_live": true, "members": [{"id": 199759, "team": {"id": 154483, "name": "Stefanos Tsitsipas", "sport_id": 5, "region_id": 0, "created_at": "2023-08-01T09:06:19.000000Z", "updated_at": "2023-08-01T09:06:19.000000Z"}, "is_home": true, "team_id": 154483, "match_id": 99966, "created_at": "2023-08-01T09:06:19.000000Z", "updated_at": "2023-08-01T09:06:19.000000Z"}, {"id": 199760, "team": {"id": 154484, "name": "John Isner", "sport_id": 5, "region_id": 0, "created_at": "2023-08-01T09:06:19.000000Z", "updated_at": "2023-08-01T09:06:19.000000Z"}, "is_home": false, "team_id": 154484, "match_id": 99966, "created_at": "2023-08-01T09:06:19.000000Z", "updated_at": "2023-08-01T09:06:19.000000Z"}], "stat_id": 22762465, "sport_id": 5, "game_info": null, "is_booked": true, "region_id": 43, "created_at": "2023-08-01T09:06:19.000000Z", "is_started": true, "is_visible": true, "live_delay": 0, "match_info": "", "risk_level": 1, "updated_at": "2023-08-03T06:49:10.000000Z", "archived_at": null, "external_id": 22762465, "is_outright": false, "live_status": 1, "is_suspended": false, "match_status": 1, "cancel_reason": "", "match_results": 0, "competition_id": 7193, "external_source": "skill90", "is_neutral_venue": false, "is_stat_available": true, "suspended_by_user": null, "information_source_id": 1}, "score": {"g": "0", "h": "0"}, "stats": {"aces": {"g": 5, "h": 7}, "game": {"g": 4, "h": 8}, "point": {"g": 21, "h": 38}, "passes": {"g": "0", "h": "0"}, "period": {"g": 0, "h": 1}, "score_set1": {"g": 2, "h": 6}, "score_set2": {"g": 2, "h": 2}, "double_fault": {"g": 2, "h": 0}, "serviceFault": {"g": 10, "h": 8}}, "clock_tm": null, "match_id": 99966, "timeline": [], "created_at": "2023-08-03T06:49:06.000000Z", "match_info": "set2", "match_time": 0, "scoreboard": {"s1": {"g": 2, "h": 6}, "s2": {"g": 2, "h": 2}, "s3": {"g": -1, "h": -1}, "s4": {"g": -1, "h": -1}, "s5": {"g": -1, "h": -1}, "s6": {"g": -1, "h": -1}, "s7": {"g": -1, "h": -1}, "sets": {"g": 0, "h": 1}, "time": "NA", "points": {"g": "0", "h": "0"}, "servis": {"g": "true", "h": "false"}, "ranking": {"g": -1, "h": -1}}, "updated_at": "2023-08-03T07:38:29.000000Z", "clock_status": null, "clock_seconds": null, "clock_direction": null, "jersey_color_away": "000000", "jersey_color_home": "000000"}, "region": {"id": 43, "name": "region.mexico", "created_at": "2023-06-21T10:41:36.000000Z", "updated_at": "2023-06-21T10:41:36.000000Z"}, "is_live": true, "members": [{"id": 199759, "team": {"id": 154483, "name": "Stefanos Tsitsipas", "sport_id": 5, "region_id": 0, "created_at": "2023-08-01T09:06:19.000000Z", "updated_at": "2023-08-01T09:06:19.000000Z"}, "is_home": true, "team_id": 154483, "match_id": 99966, "created_at": "2023-08-01T09:06:19.000000Z", "updated_at": "2023-08-01T09:06:19.000000Z"}, {"id": 199760, "team": {"id": 154484, "name": "John Isner", "sport_id": 5, "region_id": 0, "created_at": "2023-08-01T09:06:19.000000Z", "updated_at": "2023-08-01T09:06:19.000000Z"}, "is_home": false, "team_id": 154484, "match_id": 99966, "created_at": "2023-08-01T09:06:19.000000Z", "updated_at": "2023-08-01T09:06:19.000000Z"}], "stat_id": 22762465, "sport_id": 5, "game_info": null, "is_booked": true, "region_id": 43, "created_at": "2023-08-01T09:06:19.000000Z", "is_started": true, "is_visible": true, "live_delay": 0, "match_info": "", "risk_level": 1, "updated_at": "2023-08-03T06:49:10.000000Z", "archived_at": null, "competition": {"id": 7193, "name": "competition.a_t_p_los_cabos_hard", "sport_id": 5, "is_active": true, "region_id": 43, "created_at": "2023-07-29T01:58:24.000000Z", "live_delay": null, "updated_at": "2023-08-02T09:10:44.000000Z", "risk_level_live": null, "is_teams_reversed": false, "risk_level_prematch": null, "competition_risk_group": null}, "external_id": 22762465, "is_outright": false, "live_status": 1, "is_suspended": false, "match_status": 1, "cancel_reason": "", "match_results": 0, "competition_id": 7193, "external_source": "skill90", "is_neutral_venue": false, "is_stat_available": true, "suspended_by_user": null, "information_source_id": 1}, "order": 1, "price": 4, "market": {"id": "01H6X5AWAYN8XZZGAMTY5RP8K7", "name": "market.2nd_set6th_game_point2_winner", "handicap": 0, "match_id": 99966, "sequence": 0, "away_score": 0, "created_at": "2023-08-03T07:38:29.000000Z", "home_score": 0, "is_visible": true, "updated_at": "2023-08-03T07:38:29.000000Z", "external_id": "708cb00d-b77b-56eb-9cd2-af99a9d11228", "is_suspended": false, "extra_info_id": null, "market_type_id": 155987, "object_version": "0", "point_sequence": 0, "external_source": "skill90", "cash_out_available": 1, "starting_price_enabled": null, "is_selections_ordered_by_price": false}, "outcome": 0, "handicap": 0, "match_id": 99966, "market_id": "01H6X5AWAYN8XZZGAMTY5RP8K7", "source_id": null, "away_value": null, "created_at": "-000001-11-30T00:00:00.000000Z", "home_value": null, "is_visible": true, "non_runner": null, "source_key": null, "updated_at": "-000001-11-30T00:00:00.000000Z", "external_id": "3811ebb4-81b2-53ab-b8ae-4aeb6bf6c1be", "is_suspended": false, "original_price": 4, "external_source": "skill90", "selection_type_id": 369107}'); preg_match('/\{t([12])}/', $name, $matches); if (isset($matches[1])) { $team = match ($matches[1]) { "1" => array_filter($initData->match->members, fn ($member) => $member->is_home)[0]->team->name, "2" => array_filter($initData->match->members, fn ($member) => !$member->is_home)[0]->team->name, }; var_dump(array_filter($initData->match->members, fn ($member) => !$member->is_home)); if ($team) { $name = str_replace($matches[0], $team, $name); } } if (str_contains($name, '{h}')) { $name = str_replace('{h}', $initData->handicap, $name); } return $name; } echo parseName('{t2} ({h})');
Show:  
Copy Clear