0

please help me I would like to read a javascript file and retrieve only lines starting with url.instance = "www.google.fr"; in input in order to be able to modify these url

$handle = fopen('javascriptfile.js', 'r');
if ($handle)
{
    while (!feof($handle))
    {
        $buffer = fgets($handle);
        //echo $buffer."<br>";
        echo "<input type='text' value='$buffer'>";
    }
    fclose($handle);
}

I have write this code but I don't know how to continue please help me

Leonardo Alves Machado
  • 2,747
  • 10
  • 38
  • 53
etudiant
  • 35
  • 1
  • 7

1 Answers1

0

You can search each line with stripos

<?php

$handle = fopen('javascriptfile.js', 'r');
$match = 'url.instance = "www.google.fr";';

if ($handle) {

    while (!feof($handle)) {
        $buffer = fgets($handle);

        // check each line start with : url.instance = "www.google.fr";
        if (stripos($buffer, $match) === 0 ) {
            echo "<input type='text' value='$buffer'>";
        }
    }

    fclose($handle);
}
nithinTa
  • 1,632
  • 2
  • 16
  • 32