PHP code example of cryde / json-text-extractor

1. Go to this page and download the library: Download cryde/json-text-extractor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cryde / json-text-extractor example snippets


use Cryde\JsonTxtExtractor\JsonTextExtractor;

$str = <<<STR
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla elit lectus, volutpat eget turpis id, bibendum convallis erat. Ut posuere sapien felis, at ornare elit vulputate ut. 
Vestibulum egestas, diam suscipit mattis bibendum, nisi arcu ullamcorper justo.

{
  "id": "0001",
  "type": "donut",
  "name": "Cake",
  "topping": [
    {
      "id": "5001",
      "type": "None"
    },
    {
      "id": "5002",
      "type": "Glazed"
    }
  ]
}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla elit lectus, volutpat eget turpis id, bibendum convallis erat. Ut posuere sapien felis, at ornare elit vulputate ut. 
Vestibulum egestas, diam suscipit mattis bibendum, nisi arcu ullamcorper justo.

{"key": "value"}
Vestibulum egestas, diam suscipit mattis bibendum, nisi arcu ullamcorper justo.
STR;


$textJsonExtractor = new JsonTextExtractor();

var_dump($textJsonExtractor->getJsonStrings($str));
/*
array(2) {
  [0] =>
  string(184) "{
  "id": "0001",
  "type": "donut",
  "name": "Cake",
  "topping": [
    {
      "id": "5001",
      "type": "None"
    },
    {
      "id": "5002",
      "type": "Glazed"
    }
  ]
}"
  [1] =>
  string(16) "{"key": "value"}"
}

*/