What you can do in Javascript is a method that changes the content:
var content = '1|1|1|1| |1|1|1|1|1|';
alterContent(content, '123');
function alterContent(content, val) {
var add = [];
content.split('|').forEach(function(v, e){
add[e] = (e == 4 && (v == ' '|| v == '')) ? val : v;
});
return add.join('|');
}
If you need to do this for each line, just pass the method inside a loop and test each line:
var content = "1|1|1|1| |1|1|1|1|1|\n1|1|1|1| |1|1|1|1|1|\n1|1|1|1|1|1|1|1|1|1|";
var linhas = content.split("\n");
/* passa a posição 2, se usar parâmetro: null,
ignora a regra de linha, e testa todas as linhas */
alterarLinhas(linhas, '123', 2);
function alterarLinhas(linhas, val, posicao_linha) {
for (var i=0; i <= linhas.length; i++) {
if (posicao_linha != null) {
if (posicao_linha == i) {
linhas[i] = alterContent(linhas[i], val);
} else {
linhas[i] = val;
}
} else {
linhas[i] = alterContent(linhas[i], val);
}
}
return linhas.join("\n");
}
function alterContent(content, val) {
var add = [];
content.split('|').forEach(function(v, e){
add[e] = (e == 4 && (v == ' '|| v == '')) ? val : v;
});
return add.join('|');
}
1st JSFIDDLE example
2nd example JSFIDDLE
Reading, changing and recording: see this.
Also publish the relevant code, and better explain what you want sff
– Miguel
@Miguel I changed the description of the question.
– Willian Coqueiro
If you want to touch files on the client’s machine or on the server with javascript only, you can forget it. No
– Miguel
@Miguel In the client, it would only be executed by html, without apache.
– Willian Coqueiro
But you can’t read, write, change the file. "What I need and only a code to read the file, change and write"
– Miguel
I don’t know what you mean.
– Willian Coqueiro
Corrected, I made a typo
– Miguel
@Miguel I’ll have to go pro php even then. Have any idea?
– Willian Coqueiro