in

How To Use Preg_Match In php To Get Multiple Values From Json Data


i have an json data and i am trying to getting values from that my json data looks like this

{"code":0,"error":false,"message":"Team Detail","data":{"trump":null,"team1":{"id":827,"name":"Amerat Royals","sort_name":"AME","image":"https://exampe.com"},"vise_captain":{"bowl_type":" ","image":"https://exampe.com","country":"null","player_pos":3,"total_points":255.0,"selected_as_vccaption":2.45,"team_id":827,"selected_as_trump":0.0,"points":21.0,"playing_squad_updated":"Y","selected_as_caption":0.57,"is_in_substitute_squad":"N","player_id":113017,"credits":8.5,"dob":"","bat_type":" ","name":"K Sonavale","player_multiplier":1.5,"position":"batsman","is_in_playing_squad":"Y","selected_by":93.47},"team2":{"id":826,"name":"Ghubrah Giants","sort_name":"GHU","image":"https://sportasy.s3.amazonaws.com/sportasy/cricket_team/thumbnail/1989109900_1639986017_game.png"},"bowlers":[{"bowl_type":" ","image":"https://exampe.com","country":"null","player_pos":10,"total_points":166.0,"selected_as_vccaption":0.0,"team_id":827,"selected_as_trump":0.0,"points":0.0,"playing_squad_updated":"Y","selected_as_caption":0.97,"is_in_substitute_squad":"N","player_id":113028,"credits":8.5,"dob":"","bat_type":" ","name":"A Haq","player_multiplier":1.0,"position":"bowler","is_in_playing_squad":"N","selected_by":18.17},{"bowl_type":" ","image":"https://exampe.com","country":"null","player_pos":9,"total_points":280.0,"selected_as_vccaption":3.44,"team_id":827,"selected_as_trump":0.0,"points":4.0,"playing_squad_updated":"Y","selected_as_caption":1.99,"is_in_substitute_squad":"N","player_id":113026,"credits":9.0,"dob":"","bat_type":" ","name":"Bilal-Khan","player_multiplier":1.0,"position":"bowler","is_in_playing_squad":"Y","selected_by":97.35},{"bowl_type":" ","image":"https://exampe.com","country":"Oman","player_pos":11,"total_points":null,"selected_as_vccaption":26.92,"team_id":826,"selected_as_trump":0.0,"points":0.0,"playing_squad_updated":"Y","selected_as_caption":3.85,"is_in_substitute_squad":"N","player_id":113011,"credits":8.0,"dob":"","bat_type":" ","name":"I Khalid","player_multiplier":1.0,"position":"bowler","is_in_playing_squad":"N","selected_by":4.59},{"bowl_type":" ","image":"https://exampe.com","country":"Oman","player_pos":8,"total_points":202.0,"selected_as_vccaption":1.28,"team_id":826,"selected_as_trump":0.0,"points":6.0,"playing_squad_updated":"Y","selected_as_caption":0.55,"is_in_substitute_squad":"N","player_id":112999,"credits":9.0,"dob":"","bat_type":" ","name":"A Khan","player_multiplier":1.0,"position":"bowler","is_in_playing_squad":"Y","selected_by":96.12}],"team_total_credits":95.5,"captain":{"bowl_type":" ","image":"https://exampe.com","country":"null","player_pos":2,"total_points":375.0,"selected_as_vccaption":36.15,"team_id":827,"selected_as_trump":0.0,"points":4.0,"playing_squad_updated":"Y","selected_as_caption":5.58,"is_in_substitute_squad":"N","player_id":113021,"credits":9.0,"dob":"","bat_type":" ","name":"Rafiullah-M","player_multiplier":2.0,"position":"Batsman","is_in_playing_squad":"Y","selected_by":98.06},"team_total_points":94.5,"team2_selected_player":6,"name":1,"allrounders":[{"bowl_type":" ","image":"https://exampe.com","country":"null","player_pos":7,"total_points":280.0,"selected_as_vccaption":1.17,"team_id":827,"selected_as_trump":0.0,"points":4.0,"playing_squad_updated":"Y","selected_as_caption":1.17,"is_in_substitute_squad":"N","player_id":113027,"credits":8.5,"dob":"","bat_type":" ","name":"H Tandel","player_multiplier":1.0,"position":"allrounder","is_in_playing_squad":"Y","selected_by":90.65},{"bowl_type":" ","image":"https://exampe.com","country":"Oman","player_pos":5,"total_points":557.0,"selected_as_vccaption":8.63,"team_id":826,"selected_as_trump":0.0,"points":29.0,"playing_squad_updated":"Y","selected_as_caption":78.24,"is_in_substitute_squad":"N","player_id":113005,"credits":9.0,"dob":"","bat_type":" ","name":"I Latif","player_multiplier":1.0,"position":"allrounder","is_in_playing_squad":"Y","selected_by":98.06},{"bowl_type":"Right Arm Medium Fast","image":"https://exampe.com","country":"Oman","player_pos":6,"total_points":340.0,"selected_as_vccaption":31.98,"team_id":826,"selected_as_trump":0.0,"points":4.0,"playing_squad_updated":"Y","selected_as_caption":7.39,"is_in_substitute_squad":"N","player_id":62111,"credits":8.5,"dob":"1977-01-08","bat_type":"Right Hand Bat","name":"G Iqbal","player_multiplier":1.0,"position":"allrounder","is_in_playing_squad":"Y","selected_by":95.41}],"id":2420219,"wicketkeapers":[{"bowl_type":" ","image":"https://exampe.com","country":"Oman","player_pos":1,"total_points":157.0,"selected_as_vccaption":1.67,"team_id":826,"selected_as_trump":0.0,"points":4.0,"playing_squad_updated":"Y","selected_as_caption":3.33,"is_in_substitute_squad":"N","player_id":112993,"credits":8.5,"dob":"","bat_type":" ","name":"A Ullah-Qazi","player_multiplier":1.0,"position":"wicketkeeper","is_in_playing_squad":"Y","selected_by":10.58}],"batsmans":[{"bowl_type":" ","image":"https://exampe.com","country":"null","player_pos":2,"total_points":375.0,"selected_as_vccaption":36.15,"team_id":827,"selected_as_trump":0.0,"points":4.0,"playing_squad_updated":"Y","selected_as_caption":5.58,"is_in_substitute_squad":"N","player_id":113021,"credits":9.0,"dob":"","bat_type":" ","name":"Rafiullah-M","player_multiplier":2.0,"position":"Batsman","is_in_playing_squad":"Y","selected_by":98.06},{"bowl_type":" ","image":"https://exampe.com","country":"null","player_pos":3,"total_points":255.0,"selected_as_vccaption":2.45,"team_id":827,"selected_as_trump":0.0,"points":21.0,"playing_squad_updated":"Y","selected_as_caption":0.57,"is_in_substitute_squad":"N","player_id":113017,"credits":8.5,"dob":"","bat_type":" ","name":"K Sonavale","player_multiplier":1.5,"position":"batsman","is_in_playing_squad":"Y","selected_by":93.47},{"bowl_type":" ","image":"https://exampe.com","country":"Oman","player_pos":4,"total_points":167.0,"selected_as_vccaption":1.6,"team_id":826,"selected_as_trump":0.0,"points":4.0,"playing_squad_updated":"Y","selected_as_caption":2.56,"is_in_substitute_squad":"N","player_id":113003,"credits":9.0,"dob":"","bat_type":" ","name":"A Ali-I","player_multiplier":1.0,"position":"batsman","is_in_playing_squad":"Y","selected_by":55.03}],"team1_selected_player":5},"server_date":1641056841}

Now For Every Player id I need that Data Like like Position ,total points and all that

I want Final Data Like

$playerdata=”{“bat_type”:””.$bat_type.’ “,”bowl_type”:”‘.$$bowl_type.’
“,”country”:”‘.$country.'”,”credits”:’.$credits.’,”dob”:”‘.$dob.'”,”dream_team_player”:null,”full_name”:”‘.$name.'”,”image”:”‘.$image.'”,”is_in_playing_squad”:”‘.$is_in_playing_squad.'”,”name”:”‘.$name.'”,”playerType”:’.$playerType.’,”player_id”:”‘.$str.'”,”player_multiplier”:’.$player_multiplier.’,”player_pos”:’.$player_pos.’,”playing_squad_updated”:”‘.$playing_squad_updated.'”,”points”:’.$points.’,”position”:”‘.$position.'”,”selected”:true,”selected_as_caption”:”‘.$selected_as_caption.'”,”selected_as_trump”:”‘.$selected_as_trump.'”,”selected_as_vccaption”:”‘.$selected_as_vccaption.'”,”selected_by”:’.$selected_by.’,”team_id”:’.$team_id.’,”total_points”:’.$total_points.’}’;

some values coming propley with preg_match but some not what i am doing wrong



Source: https://stackoverflow.com/questions/70553916/how-to-use-preg-match-in-php-to-get-multiple-values-from-json-data

How to use one JavaScript file for two HTML files?

code wrapper for searching functionality