Alternative syntax in PHP, alternative syntax in PHP

Source: Internet
Author: User

Alternative syntax in PHP, alternative syntax in PHP

Today I read the wordpress code, which contains some rare alternative php syntax,

<?php else : ?><div class="entry-content"><?php the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'thebox' ) ); ?><?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'thebox' ), 'after' => '</div>' ) ); ?></div><!-- .entry-content --><?php endif; ?>
What do the colons and endif after else represent? I have never met a cainiao, so I just googled it to understand that this is an alternative syntax for php,

Colon (:) is equivalent to left curly braces ({), and endif is equivalent to right curly braces (});


For example:
<? Php if ($ a <0):?>
Is a negative number.
<? Php endif;?>
The preceding statement is equivalent
<? Php if ($ a <0) {?>
Is a negative number.
<? Php }?>



Which of the following statements in PHP have alternative syntaxes?
Process control (including if, while, forforeach, switch) statements have alternative syntax.


The basic form of alternative Syntax:
Replace left curly braces ({) with colons (:), and change right curly braces (}) with endif;, endwhile;, endfor;, endforeach; and endswitch;

While alternative Syntax:
<? Php while (expr):?>
<Li> cyclic Points </li>
<? Php endwhile;?>


Other Alternative syntaxes can be similar.


In CodeIgniter view, how can I write a double traversal array of the PHP alternative syntax of the file ???

Add your SQL statement

Syntax explanation in PHP

The above mentioned function is a function for reading files.
What do I mean by defining the following parameters of a sequence?

Fread ($ a, $ B );
$ A handle for reading files of the Resource Type
$ B INTEGER SIZE OF the file to be read (in bytes]

Let's look at a complete example.
<? Php
$ File = fopen ("test.txt", "r"); // open a file handle
Fread ($ file, filesize ("test.txt"); // reads the entire file filesize('test.txt '); obtains the size of the entire file in bytes.
Fclose ($ file); // close the resource handle
?>

According to my feelings, you may not understand the following questions:
1. Your concept of resource handle is not very clear;
2. You are not very familiar with fread read operations;

First:
You can simply understand the handle as a KEY for opening the file. There is no way to read or write the file without the KEY, fopen is used as a KEY generation function. It returns a file handle, that is, the KEY, for you to use.

Assume that the content of my file ("test.txt") is the following sentence (not a line break ):
'Abcdefghijk ....'
So I use fread ($ file, 3); then the returned content is three bytes of abc, and so on. $ file is the KEY used to read and write a file, 3 is the number of bytes that read the content of the file.

Note that fopen has many statuses, and r in fopen ("test.txt", "r") is read-only, and points the file pointer to the file header. This is similar to the pointer in C. You can refer to the following manual.

Related Article

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.