Add or Repalce Text in PHP
<p>I am new In PHP.I have js file look like</p>

<pre><code>   var sites = [
 //Texte anime
  {url:" http://carouselinfo.com/canal/", duration:9},
 //Texte anime
  {url:" http://carouselinfo.com/canal-2/", duration:9}, 
  //Intro detallee
 {url:"http://carouselinfo.com/index-t1.html", duration:35},
 //CTA
 {url:"http://carouselinfo.com/index-t2.html", duration:35},

 //Football
  {url:"http://carouselinfo.com/twitter-ligue/", duration:100},


 //Texte anime
  {url:" http://carouselinfo.com/canal-2/", duration:9}, 

  //TrailersClub.com
  {url:"http://trailersclub.com/?lang=fr", duration:480},

 //Heure
 {url:"http://carouselinfo.com/heure", duration:8},
 //Meteo
 {url:"http://carouselinfo.com/meteo", duration:12},
 //Texte anime
  {url:" http://carouselinfo.com/canal-cine/", duration:9},
 //Cine
 {url:"http://carouselinfo.com/cine/index-t1.html", duration:150},
  //Texte anime
  {url:" http://carouselinfo.com/canal-2/", duration:9}, 
 //Heure
 {url:"http://carouselinfo.com/heure", duration:8},
   ];
</code></pre>

<p>I want to add text after var site=[ or any line say at 4 lines using php so how can we add.Here is my code of replacing Text on any line.</p>

<pre><code>$lines = array();
foreach( file('source.js') as $line ) {
  if ( 'var site=[' === $line ) {
    array_push($lines, 'test');
  }
  array_push($lines, $line);
}

file_put_contents('source.js', $lines);
</code></pre>

<p>This code is not working out.</p>
