Find & replace JSON, PHP with Regex

I try to find and replace with regex search before I process the JSON data further. The problem is that my find and replace seems to be not working. I actually want to delete everything after the comma on each category value.

[ { "title": "Klondike", 
"thumbnail": "cdn.wanted5games.com/game-img/klondike-thumb.png", 
"description": "Classic Klondike solitaire cards patience game with two levels of difficulty and animated 3D background", 
"category": "action,adventure", 
"audience": "male,female", 
"createdAt": "2021-05-18T13:22:47.000Z", 
"width": 815, 
"height": 377, 
"assets": "cdn.wanted5games.com/game-asset/klondike.zip", 
"exclusive": 0, 
"identifier": "klondike-new-en-s-iga-cloud" }]

This is what I tried so far:

$url = 'https://portal.wanted5games.com/api/games';
$json = file_get_contents($url);
$array = json_decode($json, true); 
$products = str_replace(',.*$','',$array);

It just gives me the same output like $array. I appreciate any help!



from Recent Questions - Stack Overflow https://ift.tt/3d8GFJy
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)