Discussing how to register and use PHP variables

Source: Internet
Author: User
We will discuss how to register and use PHP variables. Starting with the smarty template, we all know that if you use this stuff to register a variable $ smarty-& gt; assign ($ aaa, '000000'); $ smarty-& gt; display ('A. tlp'); then the $ aaa variable can be used on page a. What I want to ask is. If you do not need to discuss how to register and use PHP variables.
Starting with the smarty template, we all know that if you use this stuff to register a variable $ smarty-> assign ($ aaa, '123 ');
$ Smarty-> display ('A. tlp ');
On page a, you can use the $ aaa variable. what I want to ask is. If no template is needed, how can I use a public variable on page a on page B ?? If I use Aaa;?> Is this method more efficient? After all, the template engine uses its own language logic to implement this process ..
I am at a low level and want to understand this point, please enlighten me
------ Solution --------------------
$ Smarty-> assign ($ aaa, '000000 ');
$ Smarty-> display ('A. tlp ');

Equivalent
$ A = 234;
?>
...

------ Solution --------------------
I will show you a function, which may help you.

/**
General processing engine
Metric data:
Using the parameter book and restructuring the variable value $ Arr, convert each key into a variable (if the key is a number, it will be unset)
Description:
Compile the current case name (multiple names are separated by "*"), check whether internal content is directly exported, and check whether local content is stored.
The primary memory that is not directly returned is mainly used to return the internal content after the primary memory. The purpose is to store
Return value:
If the direct statement does not return any value, if no direct statement is provided, the returned statement is later than the original statement.
Usage:
// Custom volume changes: the available volume in the volume is: $ a; $ B
$ Out = Array ('a' => 'ABC', 1 => 'fff', 'B' => Array ('ee '=>' I ', 'Yes '));

// Directly extract the two original versions of the previous version.
T ('head * Index', $ out );

// Directly extract the original statement of the previous statement.
T ('test', $ out, False );

// Return the uploaded image to the photo object
T ('test', $ out, True, 'adm ');
/**/
Function T ($ Tpl, & $ Arr = Array (), $ IsShow = True, $ Dir = 'usr '){
IF ($ Tpl = '') {Return ;}

Foreach ($ Arr as $ k =>$ v ){
IF (Is_numeric ($ k )){
Unset ($ Arr [$ k]);
IF (SYS_DEBUG) {Error ('ft0001 ', False );}
Continue;
}
$ K = $ v;
} Unset ($ Arr );

IF (! $ IsShow) {// if it is not allowed to be directly exported, you can simply capture the content.
OB_start (); OB_clean ();
}

$ Tpl = Str2Arr ($ Tpl, '*', True, True, False );
Foreach ($ Tpl as $ k => $ v ){
// Submit this case and road chart
$ FTpl = SYS_ROOT. $ GLOBALS ['sys _ TPL '. StrToUpper ($ Dir). '']. $ v.'. php ';

// Check whether the inventory exists.
IF (! File_Exists ($ FTpl) {Exit ('Error: template'. $ FTpl );}

// Merge the data into the local disk.
Require ($ FTpl );
Unset ($ FTpl );
} Unset ($ Tpl, $ Dir );

IF (! $ IsShow ){
$ M = Ob_get_contents (); // Obtain the region content
OB_end_clean (); // clear the original content OB_clean ();
OB_end_flush ();
Unset ($ IsShow );
Return $ m;
}
}

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.