0
I’m writing an application to change a particular line in an HTML file. I’ve been able to locate the word I want to replace, but for that, I need the line number to write the new content.
function changeLine(){
$file = fopen('index.html', 'r+');
while(!feof($file)) {
$conteudo = fgets($file);
if($resultado = preg_match("/<form/", $conteudo)) {
echo "Achamos!";
}
}
fclose($file);
}
I wonder if it is possible to capture the line of the HTML file that has the word '<'form.
Instead of finding the line, wouldn’t it be better to replace what you want to change? You read the file and save it to a variable, replace and write the file again.
– Sam
It could be too! I was trying to find a way to do this, I would have to make the change using the right fwrite?
– Lucas Oliveira
I believe so...
– Sam
Already asked here: How to change a specific line of a php file - In the comments you almost have the solution (just replace).
– Bacco
Brawl! I’ll take a look :)
– Lucas Oliveira