Replace word in txt using php

Asked

Viewed 35 times

0

I have the following line in the txt file

#EXTINF:-1 tvg-id="Globorj.br" tvg-name="GLOBO RJ HD" tvg-logo="https://2.bp.blogspot.com/-

this line repeats over and over again.

i need to open the txt and exchange the word tvg-namefor NOME

I tried that: $handler = fopen ( 'uploads/' . $new_name , 'r' ) ; $nova_palavra = str_replace("tvg-name", "NOME", $handler);

but it didn’t work...

  • To use with the str_replace, utilize file_get_contents instead of fopen.

  • the return of $Handler is coming in what way?

  • @Diegobraga When you use the function fopen, the variable returns a resource. In this case you cannot use with the str_replace (that expects a string). In his case, only with the file_get_contents; file and implode; or fopen + fread.

  • my full code $handler = file_get_contents ( 'uploads/' . $new_name , 'r' ) ;
 $nova_palavra = str_replace("tvg-name", "NOME", $handler);
 if ( $handler !== false ) {
 $i = 0 ; 
 $dados = array ( ) ;
 while ( ! feof ( $handler ) ) {
 $linha = fgets ( $handler ) ;
 $info = explode ( ';', $linha ) ;
 $dados [ $i ] [ 'Excluir' ] = $info [ 0 ] ;
 $dados [ $i ] [ 'Nome' ] = trim ( $info [ 1 ] ) ;
 $dados [ $i ] [ 'Link' ] = trim ( $info [ 2 ] ) ;
 ++ $i ;
 }fclose ( $handler ) ;print_r ( $dados ) ;
 }

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.