>  기사  >  백엔드 개발  >  php文件小修改,该如何处理

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

WBOY
WBOY원래의
2016-06-13 13:35:01893검색

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>
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.