国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Backend Development PHP Tutorial ThinkPHP數(shù)據(jù)模板展示——使用函數(shù)、默認值、運算符

ThinkPHP數(shù)據(jù)模板展示——使用函數(shù)、默認值、運算符

Jun 13, 2016 pm 12:12 PM
data echo name strtoupper substr

ThinkPHP數(shù)據(jù)模板顯示——使用函數(shù)、默認值、運算符

六、使用函數(shù)

1.使用函數(shù)顯示:

{$data.name|md5}

編譯后的結(jié)果是:

<?php echo (md5($data['name']));?>

?

2.如果函數(shù)有多個參數(shù)需要調(diào)用,則使用:

{$create_time | data="y-m-d",###}

表示date函數(shù)傳入兩個參數(shù),每個參數(shù)用逗號分割,這里第一個參數(shù)是y-m-d,第二個參數(shù)是前面要輸出的create_time變量,因為該哦變量是第二個參數(shù),因此需要用###標示變量位置,編譯后的結(jié)果是:

<?php echo (date('y-m-d',$create_time));?>

?

3.如果前面輸出的變量在后面定義的函數(shù)的第一個參數(shù),則可以直接使用:

{$data.name | substr=0,3}

表示輸出

<?php echo (substr($data['name'],0,3)); ?>

也可以使用:

{$data.name|substr=###,0,3} ?(沒有這個必要)

4.還可以支持多個函數(shù)過濾,多個函數(shù)之間用"|"分割即可,例如:

{$name|md5|strtoupper|substr=0,3}

編譯后的結(jié)果是:

<?php echo (substr(strtoupper(md5($name)),0,3));?>

函數(shù)會按照從左到右的順序依次調(diào)用

還可以直接這樣寫:

{:substr(strtoupper(md5($name)),0,3)}

?

七、默認值輸出

1.可以給變量輸出提供默認值,eg:

{$user.nickname|default="這家伙很懶,什么也沒留下"}

2.對系統(tǒng)變量也可以支持默認值輸出,eg:

{$Think.get.name|default="名稱為空"}

?

八、使用運算符

對于模板的輸出使用運算符,包括對 "+" "-" "*" "/" "%"的支持

注:在使用運算符的時候,不再支持點語法和常規(guī)的函數(shù)用法

{$user.age+10}   //頁面會不顯示{$user['age']+10}  //會正常的進行運算

?

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

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the most popular golang frameworks on the market? What are the most popular golang frameworks on the market? Jun 01, 2024 pm 08:05 PM

The most popular Go frameworks at present are: Gin: lightweight, high-performance web framework, simple and easy to use. Echo: A fast, highly customizable web framework that provides high-performance routing and middleware. GorillaMux: A fast and flexible multiplexer that provides advanced routing configuration options. Fiber: A performance-optimized, high-performance web framework that handles high concurrent requests. Martini: A modular web framework with object-oriented design that provides a rich feature set.

Five selected Go language open source projects to take you to explore the technology world Five selected Go language open source projects to take you to explore the technology world Jan 30, 2024 am 09:08 AM

In today's era of rapid technological development, programming languages ??are springing up like mushrooms after a rain. One of the languages ??that has attracted much attention is the Go language, which is loved by many developers for its simplicity, efficiency, concurrency safety and other features. The Go language is known for its strong ecosystem with many excellent open source projects. This article will introduce five selected Go language open source projects and lead readers to explore the world of Go language open source projects. KubernetesKubernetes is an open source container orchestration engine for automated

Laravel development: How to implement WebSockets communication using Laravel Echo and Pusher? Laravel development: How to implement WebSockets communication using Laravel Echo and Pusher? Jun 13, 2023 pm 05:01 PM

Laravel is a popular PHP framework that is highly scalable and efficient. It provides many powerful tools and libraries that allow developers to quickly build high-quality web applications. Among them, LaravelEcho and Pusher are two very important tools through which WebSockets communication can be easily implemented. This article will detail how to use these two tools in Laravel applications. What are WebSockets? WebSockets

PHP returns the ASCII value of the first character of the string PHP returns the ASCII value of the first character of the string Mar 21, 2024 am 11:01 AM

This article will explain in detail the ASCII value of the first character of the string returned by PHP. The editor thinks it is very practical, so I share it with you as a reference. I hope you can gain something after reading this article. PHP returns the ASCII value of the first character of a string Introduction In PHP, getting the ASCII value of the first character of a string is a common operation that involves basic knowledge of string processing and character encoding. ASCII values ??are used to represent the numeric value of characters in computer systems and are critical for character comparison, data transmission and storage. The process of getting the ASCII value of the first character of a string involves the following steps: Get String: Determine the string for which you want to get the ASCII value. It can be a variable or a string constant

PHP returns the string from the start position to the end position of a string in another string PHP returns the string from the start position to the end position of a string in another string Mar 21, 2024 am 10:31 AM

This article will explain in detail how PHP returns the string from the start position to the end position of a string in another string. The editor thinks it is quite practical, so I share it with you as a reference. I hope you will finish reading this article. You can gain something from this article. Use the substr() function in PHP to extract substrings from a string. The substr() function can extract characters within a specified range from a string. The syntax is as follows: substr(string,start,length) where: string: the original string from which the substring is to be extracted. start: The index of the starting position of the substring (starting from 0). length (optional): The length of the substring. If not specified, then

Go language development essentials: 5 popular framework recommendations Go language development essentials: 5 popular framework recommendations Mar 24, 2024 pm 01:15 PM

&quot;Go Language Development Essentials: 5 Popular Framework Recommendations&quot; As a fast and efficient programming language, Go language is favored by more and more developers. In order to improve development efficiency and optimize code structure, many developers choose to use frameworks to quickly build applications. In the world of Go language, there are many excellent frameworks to choose from. This article will introduce 5 popular Go language frameworks and provide specific code examples to help readers better understand and use these frameworks. 1.GinGin is a lightweight web framework with fast

Detailed explanation of the role and usage of the echo keyword in PHP Detailed explanation of the role and usage of the echo keyword in PHP Jun 28, 2023 pm 08:12 PM

Detailed explanation of the role and usage of the echo keyword in PHP PHP is a widely used server-side scripting language, which is widely used in web development. The echo keyword is a method used to output content in PHP. This article will introduce in detail the function and use of the echo keyword. Function: The main function of the echo keyword is to output content to the browser. In web development, we need to dynamically present data to the front-end page. At this time, we can use the echo keyword to output the data to the page. e

Build applications using Golang's web framework Echo framework and Docker Build applications using Golang's web framework Echo framework and Docker Jun 24, 2023 pm 03:37 PM

With the rapid development of Internet technology, Web applications have become an indispensable part of people's lives and work. How to build and deploy web applications more efficiently has also become a hot topic. This article will introduce how to use Golang's web framework Echo framework and Docker to build an efficient web application. 1. About the Echo Framework The Echo Framework is a high-performance web framework written in Golang. It is characterized by being lightweight, simple, easy to use and efficient. ByEch

See all articles