I use preg_match_all.

There is a page from which to parse a part of the code. The code itself looks like this:

<script type="text/javascript" charset="utf-8"> var elements = {"a":1,"b":2,"c":3,"d":4,"e":5}; </script> 

So I need to get only the json-part, that is, {"a":1,"b":2,"c":3,"d":4,"e":5}

If I use

 if (preg_match_all('#var wallpapers = (.*?);#si',$image_page,$matchimages,PREG_SET_ORDER)) { 

I get var elements = {"a":1,"b":2,"c":3,"d":4,"e":5};

    1 answer 1

    Check the contents of $matchimages[0][1] , there should be the desired string.

    Or try something like this:

     preg_match_all('/{[^}]*}/', $image_page, $matchimages); 
    • Well, I know that, but it will not work at all, so that initially only the value is in the array? - Shevtsov Eugene
    • You then need to specify a rule in the expression template, how to select only what you are looking for. Added an example in response. - mnv