PHP reading file into variable -
i'm trying store txt file in php variable, have functionality working already, there's 1 issue cant wrap head around.
i want read file using variables name of such file, , when so, script doesn't read file, when explicitly code name, works ok.
i have following code:
$mga_file[] = "./mga/mga_" . preg_replace("[^a-za-z]", "", trim(strtolower($ar_mga[0]))) . "_" . preg_replace("[^a-za-z]", "", trim(strtolower($db_producto))) . ".txt"; $mga_file[] = "./mga/mga_" . preg_replace("[^a-za-z]", "", trim(strtolower($ar_mga[0]))) . "_led.txt"; $mga_file[] = "./mga/mga_high_led.txt"; $mga_file[] = "./mga/mga_high_".strtolower($db_producto).".txt"; i edited code thinking variable $ar_mga[0] might have other characters, still doesn't work. using array, , following code, have different results:
foreach($mga_file $file){ $homepage = file_get_contents($file, file_use_include_path); echo "[" . $file . "] : "; echo "<pre>"; print_r($homepage); echo "</pre>"; } gives me following results:
array [$mga_file] ( [0] => ./mga/mga_high_led.txt //not working [1] => ./mga/mga_high_led.txt //not working [2] => ./mga/mga_high_led.txt //working [3] => ./mga/mga_high_led.txt //working ) as can see, file name same on 4 values, happening read file on last 2 values?
edit: seems overlooked 1 huge detail, $ar_mga[0] variable contained value trying use, enclosed on span tag (which never saw until examined page html), , never worked because of this. striping tag variable made script work correctly.
my bad!
seems overlooked 1 huge detail, $ar_mga[0] variable contained value trying use, enclosed on span tag (which never saw until examined page html), , never worked because of this. striping tag variable made script work correctly.
my bad!
Comments
Post a Comment