I want to append an HTML attribute id="active" for a link of left.php
left.php should have only one link with id="active"
The below code is actually working as per my requirement, but after a while the content of left.php is totally missing due to concurrency issues.
How can I resolve the issue?
I think we can have a java script solution for this to handle at client side. Please let me know the best solution with example.
Thank you all.
<?php
$searchF1 = ' id="active"';
$replaceW1 = '';
$searchF = basename(__FILE__).'"';
$replaceW = $searchF.' id="active"';
$myfile = fopen( 'left.php', 'rt' );
flock( $myfile, LOCK_SH );
$file = file_get_contents( 'left.php' );
fclose( $myfile );
$file = str_replace( $searchF1, $replaceW1, $file );
$file = str_replace( $searchF, $replaceW, $file );
file_put_contents('left.php', $file);
include('left.php');
?>