php - Variable works only with echo -


somebody answer why can value in echo $novotituloslug;. but, nothing in line $novalinhas .= "<link>http://localhost/votanalei/" . $novotituloslug . "</link>" . "\r\n"; , below.

function obterids($string) {     $res = preg_match('~class="artigo" id="([\w]+)"~i', $string, $ids);     if ($res == 1){             return $ids[1];     } else {             return "";     }       }  $linhas = explode("<ul", $documento);  $novalinhas = "";  foreach ($linhas $novalinha){      $novotituloslug = obterids($novalinha);     echo $novotituloslug . "<br>"; // apenas para teste.      $novalinhas .= "<link>http://localhost/votanalei/" . $novotituloslug . "</link>" . "\r\n";     $novalinhas .= "<wp:post_name>" . $novotituloslug . "</wp:post_name>" . "\r\n"; }   $file = fopen("test.txt","w"); $results = fwrite($file,$novalinhas); fclose($file); 

with var_dump($novotituloslug); below echo line, got:

string '' (length=0)  artigo1  string 'artigo1' (length=7)  artigo2  string 'artigo2' (length=7)  artigo3  string 'artigo3' (length=7) 

in function obterids, if remove content , paste return "teste"; print me value.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -