-2

i have a bot for daily match. But i can't figure out how it will be exactly replace tags, for example i have data like this;

{"id":"45961","title":"Independien - Sporting Cri","type":"1","flag":"tr","date":"2017-03-17 03:45:00","date":"03\/17\/2017 04:32:55","live":"1"},{"id":"45962","title":"Independien - Sporting Cri","type":"1","flag":"tr","date":"2017-03-17 03:45:00","date":"03\/17\/2017 04:32:55","live":"1"}

Code:

$connect = sanitize_output(connect("h****"));

preg_match_all('@{"id":"(.*?)","title":"(.*?)","type":"(.*?)","flag":"(.*?)","time":"(.*?)","time":"(.*?)","live":"(.*?)"}@si',$connect,$football_t);   

$id=$football_t[0][0];
$title=$football_t[0][1];

vs.

With this use i can't select datas, I want to do table with foreach but i can't figure out how it will be.

Barmar
  • 741,623
  • 53
  • 500
  • 612
Zeki
  • 1
  • 1
  • 2
    Don't use a regular expression to parse JSON. Use `json_decode()`. – Barmar Mar 17 '17 at 01:50
  • @Zeki please delete your question because it is a duplicate and that is a no-no on StackOverflow. Paul's link is 100% a duplicate which was deliberately created to stop SO getting bloated with duplicate questions like yours. – mickmackusa Mar 17 '17 at 02:10

1 Answers1

1

Use json_decode() to parse a JSON string, not a regular expression.

$data = json_decode($connect);
$id = $data->id;
$title = $data->title;

You also shouldn't sanitize JSON, that may prevent json_decode() from parsing it properly.

Barmar
  • 741,623
  • 53
  • 500
  • 612