How to use variable in php array read from file -
i trying figure out how use variable in array has been read file. have far , returning variable name instead of value. example intentionally not have space between $var.doe , saint.$var , places $var in front of "doe" , behind "saint" because actual data dealing with. thank help.
read.txt
$var.doe saint.$var
php file
<? $var = "john"; $aarray = file('read.txt'); echo $aarray[0]; echo '<br>'; echo $aarray[1]; ?>
you need substitute variables:
php > $s = ' $var.doe saint.$var '; php > echo $s; $var.doe saint.$var php > $var = 'jone'; php > echo str_replace('$var', $var, $s); john.doe saint.john
Comments
Post a Comment