Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

636
Views
PHP / cURL or file_get_contents -- How to get the value of a JS page instead of the JS code

This is hopefully an easy question, but it's giving me an issue. I have a page "sample.html" with a simple script like this in JS:

// sample.html
<script>
    let myNumber = 15;
    document.write(myNumber);
</script>

... and then I want to have a PHP page ("getValue.php") go and get that number (e.g., 15). My problem is: If I do a file_get_contents or even a cURL to that JS page, like so...

// getValue.php
$newVal = file_get_contents('sample.html');

... the $newVal var in PHP is NOT simply the "15" value. Instead, the var is equal to the entire JS script shown. So, how can I use PHP to get that "15" value alone as a variable? In other words, I only want $newVar to be the result of the JS page, not the entire script. What I want to achieve is:

// $newVal == 15

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

TL;DR

With file_get_content you cant do that.

You looking for a php scrapper of JavaScript genertaed content. One tool would be PHP-Webdriver. It base on Selenium.

https://github.com/php-webdriver/php-webdriver

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!