PHP_Bibel reading and learning (1) reading books and reading classics, writing text and writing code-tough

Source: Internet
Author: User
Tags flock
PHP_Bibel reading and learning (1) -- reading books and reading classics, writing text and writing code-Ren also quickly looks at it, and then there are new and interesting reading every day.

This book is well received by many people, such as 'php and MySQL Web developer', the mechanical industry Publishing House, and the Australian author. if you are interested, you can take a look.

Article 1 use PHP

I. Getting started

In five minutes, click two.

1
 "; 15 $ B = & $ a; 16 echo $ B; echo"
"; 17 $ B = 3333; 18 echo $ a; echo"
"; 19 20 // execution operator 21 // ''22 $ out = 'ls-LA'; 23 echo'
'.$out.'
';

II. data storage and retrieval (direct file operations

All you want to talk about is in the code.

1 namespace Bible \ Basic \ DataUsing; 2 // Determine whether the file exists -- open the file -- lock the file -- read the file -- write data -- Unlock -- close the file 3 then filename='test.txt '; 4 if (! File_exists ($ filename) {5 echo 'The file you want to visit is not exist! '; Echo"
"; 6 exit; 7} 8 $ fp = @ fopen ($ filename, 'R + '); 9 flock ($ fp, LOCK_EX); // lock the file, only one write 10 while (! Feof ($ fp) {// read file content by row 11 $ content = fgets ($ fp); 12 echo $ content; echo"
"; 13} 14 $ writeContent = 'I have something to write in'; 15 fwrite ($ fp, $ writeContent, strlen ($ writeContent); // control the write length, compatibility consideration 16 flock ($ fp, LOCK_UN); // release lock 17 fclose ($ fp );

3. array

Other things are commonplace. you may find out what you want to use. this is just a matter of proficiency, but you still have to know.

Then I learned the advantages of usort (user-defined sorting:

1 // Chapter3.Array 2 namespace Bible \ Basic \ ArrayUsort; 3 // multi-dimensional array sorting 4 $ array1 = array (54654,545,668); 5 $ array2 = array (5454,88, 37,54 ); 6 $ array3 = array (123,4444, 5453); 7 $ arrayAll = array ($ array1, $ array2, $ array3); 8 var_dump ($ arrayAll ); 9 10 function dimensionsCompare ($ x, $ y) 11 {12 if ($ x [1] = $ y [1]) {13 return 0; 14} elseif ($ x [1] <$ y [1]) {15 return-1; 16} else {17 return 1; 18} 19} 20 @ usort ($ arrayAll, "dimensionsCompare"); 21 var_dump ($ arrayAll );

Other explode is a little fun.

IV. string operations and regular expressions

String sorting

1 $name=trim($_POST['name']);2 $email=rtrim($_POST['email']);3 $feedback=chop($_POST['feedback']);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.