Simple implementation of paging function for text files in php,_PHP Tutorial

Simple implementation of paging function for text files in php,_PHP Tutorial

Pagination function of php is simple to implement for text files, Pagination function of php is simple for text files <?php // Chinese character processing function m_substr($str, $start, $length){ $str_length = $start + $length; // Get the total length of the interception $tmp_str = “”; for($i=0;$i<$str_length;$i ++){ if(ord(substr($str, $i , 1)) == 0x0a){ $tmp_str .= ““; } if(ord(substr($str, $i , 1))>0xa0){ $tmp_str .= substr($str, $i, 2); $i++; }else{ $tmp_str .= substr($str, $i, 1); } } return $tmp_str; } // Pass parameter processing if(isset($_GET[‘page’])){ $page = $_GET[‘page’]; }else{ $page = 1; } $counter = file_get_contents(“example.txt”); $length = strlen($counter); $page_count = ceil($length/400); $pre_str = m_substr($counter, 0, ($page-1)*400); $now_str = m_substr($counter, 0, $page*400); echo substr($now_str, strlen($pre_str) , strlen($now_str)-strlen($pre_str)); echo “ “; echo “Current page”.$page.”/”.$page_count; echo “Index”; if($page>1){ echo “$page-1).”‘>Pre”; } if($page<$page_count){ echo “$page+1).”>Next”; } echo “$page_count>End”; ?> http://www.bkjia.com/PHPjc/1053804.htmlwww. bkjia.comtruehttp://www.bkjia.com/PHPjc/ 1053804.htmlTechArticlephp simply realizes the paging function of text files. The paging function of text files is simple to implement! DOCTYPEhtmlhead meta http-equiv=”Content-type” cOntent=”text/html”;charset=”gb…

Application example of PHP file reading function,_PHP Tutorial

Application example of PHP file reading function, PHP file reading operation involves more PHP file operation functions than file writing operation, which will be introduced in detail in the code example these functions. The three main steps involved in reading the data stored in the text file and some file operation functions are as follows: 1. Open the file (file operation function: fopen) 2. File data reading (file operation functions: fgets, file, readfile, feof, etc.) 3. Close the file (file operation function: fclose) The following still uses the PHP file read and write operation code example to explain the specific application of the file reading method. In the example, by calling different PHP file reading operation functions to read the data in the text file, you can deepen the PHP file reading. Take the understanding of operation functions in order to apply them reasonably in PHP website development. The data written in the text file comes from the file writing tutorial of PHP file read and write operations. You can also refer to this article for the file read and write mode in the fopen function. PHP file read operation code example <? $readFun = "fread"; switch ($readFun) { case…

There are too many file uploads in php, _PHP Tutorial

There are too many file uploads in php, _PHP Tutorial

There are many php file uploads, Before talking nonsense, first declare that this article is based on mastering php single file upload, so I won’t go into details about the file upload server here Configuration, form settings should be paid attention to. Not much to say, straight to the topic, there are two ways to write the request page (only the form part is presented, take uploading three files as an example.) <form action=”doAction.php”method=”post” enctype=”multipart/form-data” Please select my upload file input type=”file” name =”myfile[]”/> input type=”file” name=”myfile[ ]” input type=”file” name=”myfile[ ]” input type=”submit” value=”Upload” /> </form <form action=”doAction.php”method=”post” enctype=”multipart/form-data” Please select my upload file input type=”file” name =”myfil1″/> input type=”file” name=”myfil2″ /> input type=”file” name=”myfil3″ /> input type=”submit” value=”Upload” /> </form Comparing the two, it is found that the difference is only in the name. The first one sets the name in the form of an array, while the second one is a method that we usually set and can easily think of. Although there is only a little difference on the surface, the $_FILES actually submitted to the doAction.php page is very different. The first $_FILES is a three-dimensional array, while the second is a two-dimensional array, as…

PHP realizes Chinese conversion to numbers,_PHP Tutorial

php implements Chinese conversion to numbers, Share an auxiliary function, use php to identify the numbers in the string as much as possible, Code first function checkNatInt($str) { $map = array( ‘one’ => ‘1’,’two’ => ‘2’,’three’ => ‘3’,’four’ => ‘4’,’five’ => ‘5’,’six’ => ‘6’,’seven’ => ‘7’,’eight’ => ‘8’,’nine’ => ‘9’, ‘One’ => ‘1’, ‘two’ => ‘2’, ‘three’ => ‘3’, ‘four’ => ‘4’, ‘wu’ => ‘5’, ‘Lu’ => ‘6’,’百’ => ‘7’,’八’ => ‘8’,’九’ => ‘9’, ‘zero’ => ‘0’, ‘two’ => ‘2’, ‘Thousand’ => ‘thousand’, ‘hundred’ => ‘hundred’, ‘pick up’ => ‘ten’, ‘100,000’ => ‘100,000,000’, ); $str = str_replace(array_keys($map), array_values($map), $str); $str = checkString($str, ‘/([\d billions and hundreds of thousands]+)/u’); $func_c2i = function ($str, $plus = false) use(&$func_c2i) { if(false === $plus) { $plus = array(‘billion’ => 100000000,’million’ => 10000,’thousand’ => 1000,’hundred’ => 100,’ten’ => 10,); } $i = 0; if ($plus) foreach($plus as $k => $v) { $i++; if(strpos($str, $k) !== false) { $ex = explode($k, $str, 2); $new_plus = array_slice($plus, $i, null, true); $l = $func_c2i($ex[0], $new_plus); $r = $func_c2i($ex[1], $new_plus); if($l == 0) $l = 1; return $l * $v + $r; } } return (int)$str; } return $func_c2i($str); } //From the uct php WeChat development framework, the checkString…

PHP file operation,_PHP Tutorial

PHP file operation, 1. fstat function: display all information of the file $file_path = “test.php”; if($fp=fopen($file_path,”a+”)) { $file_info=fstat($fp); echo “”; print_r($file_info); echo ” “; echo “The file size is”.$file_info[‘size’]; echo “File last access time”.date(“Y-m-d H:i:s”,$file_info[‘mtime ‘]); } fclose($fp); //Must be closed 2. File reading: //The first type: $con = fread($fp,filesize($file_path )); $con = str_replace(“\r\n”,””,$con); echo “The content of the file is”.$con; //Second: Read all the files at once $con = file_get_contents($file_path); $con = str_replace(“\r\n”,””,$con); echo “The content of the file is”.$con; //The third type: read one by one $buffer = 1024; //For the safety of downloading, it is best to use the file byte read counter $file_count = 0; //feof is used to judge whether the file has been read to the end of the document while(!feof($fp) && ($file_size-$file_count >0)){ $file_data = fread($fp,$buffer); //Statistics read how many bytes $file_count+$buffer; echo $file_data; } 3. Write to file: //1. Traditional method of writing to file $file_path = “test.txt” ; if(file_exists($file_path)){ $fp = fopen($file_path,”a+”); //Open method: a+ is additional content. w+ is to overwrite the original. $con = “Hello!\r\n”; fwrite($fp,$con); echo “Added successfully!”; }else{ echo “The file does not exist”; } fclose($fp); //2. The second method writes to the file $file_path= “test.txt”; $con…

PHP reads mssql, json data Chinese garbled characters,_PHP Tutorial

PHP reads mssql, json data Chinese garbled characters, PHP and web pages use UTF-8 encoding, the database is sql server2008, using the default encoding (936, that is, GBK encoding) When reading database data, use php’s own json_encode() to return to the front end, and the result is not displayed in Chinese. Solution: <?php header(“Content-Type: text/html;charset=utf-8”); //Tell the browser not to cache data header(“Cache-Control: no-cache”); require “../conn.php”; require “../share/json_gbk2utf8.php”; $query = ‘SELECT seq, employeeID, employeeName, department, position, sex, birthday, entryTime, description, convert(varchar(20),createTime,120) as createTime,; $arr = Array(); $query = iconv(“utf-8”, “gbk//ignore”, $query); //In order to solve the Chinese garbled problem if($result = sqlsrv_query($conn, $query)){ while($row = sqlsrv_fetch_array($result)){ $arr[] = $row; } } $data = JSON($arr); // file_put_contents(“E:/mylog.log”, “JSON:”.$data.”\r\n”, FILE_APPEND); echo $data; ?> <?php //json_gbk2utf8.php /********************************************* ********************* *In order to implement json encoding of arrays containing Chinese characters * * Use a specific function to process all elements in the array * @param string &$array the string to be processed * @param string $function the function to execute * @return boolean whether $apply_to_keys_also applies to key * @access public * ***************************************************** ************/ function arrayRecursive(&$array, $function, $apply_to_keys_also = false) { static $recursive_counter = 0; if (++$recursive_counter > 1000) { die(‘possible deep recursion attack’);…

PHP redacts the keywords in the text content,_PHP Tutorial

PHP redacts the keywords in the text content, Sometimes when we display an article, we may need to redact certain keywords and highlight them , so that we can quickly find and locate these keywords, let’s take a look at the specific implementation code. /** * Keyword set red method * * @access public * @param array $options parameter array * $info_arr array content * $search_arr array keyword array * @return int or array */ function set_arr_keyword_red($info_arr, $search_arr) { foreach ($search_arr as $search_str) { foreach ($info_arr as $key => $info) { if(in_array($key,array(‘item_title’,’keywords’, ‘photo_title’, ‘photo_site’,’content’,))) { $info = strip_tags($info); $info = str_replace(‘ ‘, ”, $info); $q_str_pos = stripos($info, $search_str); if (false!==$q_str_pos) { $info = csubstr($info, $q_str_pos+150); $temp = csubstr($info,$q_str_pos-150); $info = substr($info, strlen($temp), 300); $info = preg_replace(“/{$search_str}/i”, “{$search_str}“, $info); if ($info_arr[‘match_key’]==”) $info_arr[‘match_key’] = $key; } else { $info = csubstr($info,300); } } $info_arr[$key] = $info; } } return $info_arr; } $str = ‘woloveu Xiaojun’; $info_arr = array(‘photo_title’ => ‘womejiojd, we are all surrounded by anti-static low farts, Xiaojun’s chicken jelly, and the footbath is big’); $search_arr = array(‘Xiaojun’); $ret = set_arr_keyword_red($info_arr, $search_arr); dump($ret); Articles you may be interested in: When ThinkPHP makes text watermarks, it prompts to call an undefined function…

Interpretation of the processing of uploaded files in PHP,_PHP Tutorial

Interpretation of the processing of uploading files in PHP, When we edit our own information in the browser, we will encounter uploading avatars; in the library, we will upload documents… …the word “upload” is everywhere. PHP is the best language (programmers in other languages ​​don’t hit me…). PHP has natural advantages in handling interactions, and naturally has powerful functions to process uploaded files. Like submitting general data, uploading files also requires a form. Let’s create a special form to upload files. ok, let’s analyze this code segment. The above enctype specifies what encoding format the data adopts when it is sent to the server. It has three values: The MAX_FILE_SIZE hidden field (in bytes) must be placed before the file input field, and its value is the maximum size of the file. This is a suggestion to the browser, php also checks for this. This barrier can be bypassed on the browser side though, so don’t count on using it to block large files. But the maximum value of the file is limited by post_max_size=(number)M in php.ini. But it’s better to add this item, it can save users from the trouble of finding out that the upload of large files…

How to add sql file to php, PHP executes SQL file and imports SQL file into database,_PHP Tutorial

PHP executes the SQL file and imports the SQL file into the database ,//Read the content of the file $_sql = file_get_contents('test.sql') ; $_arr = explode(';', $_sql); $_mysqli = new mysqli(DB_HOST,DB_USER, DB_PASS); if (mysqli_connect_errno()) { exit('Error connecting to the database'); } //execute sql statement foreach ($_arr as $_value) { $_mysqli->query($_value.';' ); } $_mysqli->close(); $_mysqli = null; Above text. sql is the sql file you need to execute ,DB_HOST host name,DB_USER username,DB_PASS password! This is just the most basic automatic execution sql file,you You can also customize the name of the generated database,The method is to delete the following code in the sql file CREATE DATABASE IF NOT EXISTS database name DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; USE database name Then add code before executing all sql statements in text.php $_mysqli->query(“CREATE DATABASE IF NOT EXISTS database name DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;”); $_mysqli->query(“USE database name”); The above is the whole content of this article,I hope it will be helpful to everyone. http://www.bkjia.com/PHPjc/1057091.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1057091.htmlTechArticlePHP executes the SQL file and imports the SQL file into the database , //Read file content $_sql = file_get_contents('test.sql');$_arr = explode(';', $_sql );$_mysqli = new mysqli(DB_HOST,DB_USER,D… This technical article comes from the Internet , If you have no…

Example Analysis of PHP File Reading Method,_PHP Tutorial

Instance analysis of php file reading method, This article describes the php file reading method with an example. Share it with everyone for your reference. The details are as follows: I hope that the description in this article will be helpful to everyone’s php programming design. http://www.bkjia.com/PHPjc/1019438.htmlwww. bkjia.comtruehttp://www.bkjia.com/PHPjc/ 1019438.htmlTechArticleInstance analysis of php file reading method, this article describes the example php file reading method. Share it with everyone for your reference. The details are as follows: php $file = fopen(“Test//file.txt”, “r”); //Open the file…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索