Home >Backend Development >PHP Tutorial > php文件小修改,该如何处理

php文件小修改,该如何处理

WBOY
WBOYOriginal
2016-06-13 13:35:01957browse

php文件小修改
一个读取数据库内容添加到txt里面的php文件,想要在读取的内容前面或者后面加上内容,该怎么写?比如"前缀+内容+后缀"
加号是省略的

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><?php $cn = mysql_connect('localhost','root','');
if( $cn )
{
 $files=glob("*.txt");
 foreach($files as $file)
   unlink($file);

mysql_connect("106.187.43.139", "caijizhi_123", "7898585") or
        die("Could not connect: " . mysql_error());
    mysql_select_db("caijizhi_123");
    $result = mysql_query("SELECT title FROM cjx_archives") or die(mysql_error());         
   $file_index=1;
   $i=1;
    while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
        if(! ($i % 150) ) $file_index++;
$i++; 
        file_put_contents ( $file_index.'.txt' , $row[0].  PHP_EOL, FILE_APPEND );  
    }
    mysql_free_result($result);
    }
else
{
 die('连接失败');
}

?>


------解决方案--------------------
PHP code

//先定义好 $prefix, $suffix的值,说白了就是字符串连接问题。。你能写这些代码,字符串连接不会?

file_put_contents ( $file_index.'.txt' , $prefix . $row[0] . $suffix . PHP_EOL, FILE_APPEND ); <div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn