User tips: PHP Web Development Kohana framework of several writing

Source: Internet
Author: User
Tags comparison lowercase php file php web development require kohana

1, character comparison:

Comparisons apply to comparing whether a character is case-sensitive:

Program code

$class = ' RFDSAFFSADFSADFASDFSADF ';
$type = ($class [0]< ' a ')? ' Libraries ': ' Helpers ';
Echo$type;

Program code

Echo (' Uppercase A: ');
Echoord (' A ');
Echo (' Echo (' lowercase a: ');
Echoord (' a ');

Output is: Uppercase a:65 lowercase a:97

1, such comparisons should be first converted to ASCII comparison;

2, the first character is Chinese, with $class[0] this way can not be taken out!

3, $class [0] Such a way is not recommended, I have a little forget, should be 4.0 before the writing, should recommend using $class{0}

4, compared with Chinese, you can use Ord (Mb_substr ($class, 0,1, ' utf-8 ')) >127, here is to take the first character and then turn to ASCII, and then compare, greater than 127, may be considered Chinese;

2, First letter capital

Have a relationship with the above, also remember;

Makeastring ' Sfirstcharacteruppercase

Program code

Ucfirst ()

The example in the manual is this:

Program code

<?php
$foo = ' helloworld! ';
$foo =ucfirst ($foo);//helloworld!
$bar = ' helloworld! ';
$bar =ucfirst ($bar);//helloworld!
$bar =ucfirst (Strtolower ($bar));//helloworld!
?>

3, automatic loading

have been curious before, the class file has not require come in, how can directly use it?

The function appears to be supported after a few 5 points;

not supported before;

Spl_autoload_register (Array (' Kohana ', ' auto_load '));

Then the Kohana can be written like this:

Program code

Finalclasskohana

{
Publicstaticfunctionauto_load ($class)

{
Require$class. '. PHP ';
}
}
In this way, you newabc (), as long as the abc.php file exists, will be directly require in;

You should know what it means to have a look.



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.