3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = 'Details: [fieldPath: id; trigger: Invalid predicate name: id; errorString: SelectorError.INVALID_PREDICATE_FIELD_NAME]'; // strip out details and [] $str = str_replace(['[',']', 'Details:'], '', $str); // fix name and replace seperators $str = str_replace([': ', ';', ' name='], ['=', '&', '&name='], $str); // parse string into $array variable parse_str($str, $array); $json = ['Details' => $array]; print_r(json_encode($json, JSON_PRETTY_PRINT));
Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
{ "Details": { "fieldPath": "id", "trigger": "Invalid predicate", "name": "id", "errorString": "SelectorError.INVALID_PREDICATE_FIELD_NAME" } }

preferences:
109.72 ms | 403 KiB | 158 Q