Skip to content
Advertisement

Parse JSON data inside from occurrence of script tag using SimpleHtmlDom – PHP

I am using simple html dom to parse a link that contains two script tags with type=application/ld+json.

The target website structure is like below,

JavaScript

Now as I showed above I just want to parse the data inside the first , For this I am using following code

JavaScript

As I am trying to extract the first occurrence of by specifying “0” in find() function but that give me the following error.

JavaScript

Anyone knows what I am doing wrong or how can I fix this? Thanks

Advertisement

Answer

If you specify the index of the instance you want, you only get that element back and not a list, so the loop isn’t required (in fact is the problem)…

JavaScript

Just for reference, the code from find()

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement