I am new In PHP.I have js file look like
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},
];
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.
$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);
This code is not working out.
This would append to your file if that’s what you’re trying to do.
If you want to replace the text in that location you can just
If you want to place a new link at line 4, shift the array to the right and write at array location 3 (
$lines[3]). Or you can use my function:Use the function like this if you want to insert “test” at index 4:
array_insert($array, 4, "Test")I haven’t tested but it should work.