I want to display the contents of a json script with the help of simple HTML Dom and my goal is to display the second "@type": "user" name and url feed:
my Json :
<script type="application/ld+json">
"type": {
"@type": "Type",
"name": "admin"
},
"offers": {
"@type": "AggregateOffer",
"offerCount": "30"
,"offers": [
{
"@type": "user",
"name": "abc",
"url": "https://test.com",
},{
"@type": "user",
"name": "eds",
"url": "https://example.com",
},{
"@type": "user",
"name": "gfh",
"url": "https://test.com",
},{
"@type": "user",
"name": "dfc",
"url": "https://test.com",
},
.
.
.
My desired output: "name": "eds", "url": "https://example.com"
For this I am using following code:
$json = $html->find('script[type="application/ld+json"]',0);
echo $json->innertext;
But this code shows me all the json contents, I really don't know how to make a condition in my code that only the second "@type": "user" name and url feed from this complex cycle will be displayed to me
Assuming your HTML and JSON are valid:
UPDATE: There are other errors in the page that prevent the parser from working. I suggest using a function to extract the script tag text.