Home > Backend Development > PHP Tutorial > How to use the PHP variable php_self to implement intra-page jump_PHP tutorial

How to use the PHP variable php_self to implement intra-page jump_PHP tutorial

WBOY
Release: 2016-07-15 13:32:30
Original
943 people have browsed it

We may be interested in

. The in-page jump here is not equal to the jump of html bookmarks, but the PHP program changes the tail parameter of the URL. Provide different web content in the same program. Try comparing the following two URLs:

http://www.gxblk.com/pc/index.php

http://www.gxblk.com/pc/index.php? page=2

The difference between the above two URLs is that the second URL address has one more parameter (?page=2). When we actually open them, the content we get in the browser is different. , and they jump within the same page when clicked. This is achieved using the PHP variable php_self. The PHP program written by the user will generate different content according to the different tail parameters of index.php, but they all use the same web page program (index.php), so we call it "in-page" Jump", in fact, it generates another Web document.

We already know from the second URL address above that the built-in variable $php_self uses question marks to guide parameters. The specific expression format is as follows:

$php_self?Variable name = value (example: $php_sefl? id=0)

The variable name after the question mark is customized. Usually, it is named as a more readable English name (can be an abbreviation) as needed. For example, if we let the link point to a certain function block of the program to complete a deletion operation, then we can name it $del, which is reflected in the code as $php_self?del= value. If the link is clicked, the program will execute Delete operation (of course, the deletion operation code must be written separately):

Link code:

<ol class="dp-xml">
<li class="alt"><span><span>print   </span></span></li>
<li>
<span>"</span><span class="tag"><</span><span> </span><span class="tag-name">a</span><span> </span><span class="attribute">href</span><span>="$php_self?</span><span class="attribute">del</span><span>=</span><span class="attribute-value">true</span><span>"</span><span class="tag">></span><span> </span>
</li>
<li class="alt"><span>删除选定内容  </span></li>
<li>
<span class="tag"><</span><span> /a</span><span class="tag">></span><span>"; </span>
</li>
</ol>
Copy after login

Jump code:

<ol class="dp-xml">
<li class="alt"><span><span>if($</span><span class="attribute">del</span><span>=="true")  </span></span></li>
<li><span> {  </span></li>
<li class="alt"><span>//这里是删除代码  </span></li>
<li><span>} </span></li>
</ol>
Copy after login

The PHP variable php_self can take multiple parameters. The first parameter is guided by a question (?), and the subsequent parameters are guided by an ampersand (&). The format and examples are as follows:

[Syntax]$php_self?Variable1=value&Variable2=value&Variable3=value

[Example]$php_self?user=blackhorse&id=write&page=0

In principle, $php_self The tail parameters of should be written together, but the variables connected with the ampersand can be separated by spaces or other valid symbols (such as the + sign) - sometimes we do need to separate them, for example, to pass arv verification, the symbol & There will be some impact. The HTML code generated after separation is recognized by arv.

The PHP variable php_self is a very useful built-in variable in PHP, which is usually used for paging, performing predefined operations, etc. Each variable in the tail parameters it carries can be read using $ in php, such as the following address:

http://www.gxblk.com/pc/index.php?page=3

We will read the page number from the above address and display the content of the page like this:

$conts=echo_conts($page);

echo_conts is a self-written function, which uses For displaying the content of each page, the value of the variable $page is the key. It determines the content range that the program extracts from the library file.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446122.htmlTechArticleWe may not mean that the in-page jump here is a jump like an html bookmark, but a php program Provide different web content in the same program by changing the tail parameters of the URL. Try to compare...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template