get values from txt file in php
i know this will be easy for you but not for me :)
i need to get the contents of txt file "file.txt"
file.txt contetnt is
word1 word2 word3
each in a new line or can be as word1, word2, word3,
or "word1", "word2", "word3",
whichever is easier to do.
i have config.php
file which i need it to read all and every word in file.txt
and process as $value
to be then processed by script.php
which process $value
as a single word of all the words in file.txt
thanks
Assuming your file.php is as
<?php
$words = array("word1", "word2", "word3");
?>
In another php file , say read.php, you can access file.php as
<?php
include "file.php";
print_r($words);
foreach($words as $value){
echo $value;
//do whatever you want to do with each word
}
?>
foreach($lines as $value)
$words= explode("t",$value);`
每个使用内部爆炸
Here you go. Let me know if you require an explanation about the code
<?php
$file = "filename.txt";
$content = file_get_contents($file);
$value = "";
foreach (explode("n", $content) as $line) {
// line is "word1", "word2", "word3", etc.
$value .= $line . " ";
}
$value = trim($value); // Remove trailing space
链接地址: http://www.djcxy.com/p/96564.html
上一篇: 带有OOP的OOPS,PHP数据库连接
下一篇: 在php中从txt文件获取值