0

I want to get the specific content from script tags from a web page.
Here is HTML page.

<html>
    <head>
        <title></title>
       <script>
         //some other srcipt code
       </script>
    </head>
<body>
       <script>
         //some other srcipt code
       </script>
    <!-- some other html code -->
<script>
var abc = {"asld":"asdjk","thisone":"https:\/\/www.example.com\/$N.jpg|#1000#M$M#JSuL8|1000#M$M#fW4EC0jcOl8kUY_QBZbOASsF8t0","user_gender":"m"};
</script>

</body>
</html>   

I want to get only this value fW4EC0jcOl8kUY_QBZbOASsF8t0 which is in the last attribute of thisone in a script variable var abc.
Can I do this with PHP HTML DOM. If no then how can I do

1 Answer 1

1

You can easily get it using the regex

"thisone":".*#(.*)",

Assuming, the webpage is http://example.com,

$data = file_get_contents('http://example.com');
preg_match_all("/\"thisone\":\".*#(.*)\",/", $data, $output);
echo $output[1][0]; // prints fW4EC0jcOl8kUY_QBZbOASsF8t0

Hope that helps!

Sign up to request clarification or add additional context in comments.

2 Comments

This is working but this one is very slow any other method which is faster.
Then how can I get last video in kind of script let asVideoJson = [{"web":"https:\/\/ufac4.net\/","src":"https:\/\/video\/c2FnYW1lc2FnYW1lc2FnYW1lc2FnYW1lc2FnYW1lc2FnYW1l\/Ufac4.mp4","type":"video\/mp4"},{"web":"https:\/\/brazil999.net\/","src":"https:\/\/video\/c2FnYW1lc2FnYW1lc2FnYW1lc2FnYW1lc2FnYW1lc2FnYW1l\/brazil999.mp4","type":"video\/mp4"},{"web":"https:\/\/hotgraph881.com\/","src":"https:\/\/video\/c2FnYW1lc2FnYW1lc2FnYW1lc2FnYW1lc2FnYW1lc2FnYW1l\/hotgraph88.mp4","type":"video\/mp4"}];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.