-1

I am trying to make a card reader for cardcast. I get these cards in a string using file_get_contents and then need to extract the text for each card.

Here is an example piece of the string for one card, each one of these cards is separated by a comma and has the parentheses on either end.

{"id":"030b3406-55ae-4159-9129-04463c61973c","text":["Why does this not work? ",""],"created_at":"2017-06-04T15:13:42+00:00","nsfw":true}

I am trying to extract just the information inside the text tag, in this case ' Why does this not work? ","" ' (minus the single quotes and white space on both ends).

Could someone please help to extract this information using split or regex? I could do this slowly with split but I assume it is more efficient to use regex as there could be multi-hundred cards and this needs to be time efficient.

I looked into preg_match() but did not understand it well enough to get a functioning version.

Thanks

Zac Warham
  • 158
  • 11
  • https://stackoverflow.com/questions/3690614/how-to-do-regex-in-following-data-using-php – revo Jun 25 '17 at 16:07

2 Answers2

1

Looks like a JSON encoded text.

Simply decode the text using 'json_decode()'

JSON: JavaScript Object Notation.

JSON is a syntax for storing and exchanging data.

JSON is text, written with JavaScript object notation.

You can learn more about json here :

http://www.json.org/

https://www.w3schools.com/js/js_json_intro.asp

Niv Apo
  • 983
  • 1
  • 9
  • 18
1

change json to php array with -> $array=json_decode($json,true)

get ur text attribute:

$array['text']