Get the App
SLTechnology News&Howtos  ›  Development  › 

How to replace sprintf in php

Shulou Source: shulou.com Published: 2022-06-02 06:02:08 10月03日 Update

Editor to share with you how to replace sprintf in php, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Php sprintf to achieve replacement methods: 1, to create a PHP sample file; 2, through "sprintf (" There are% u million cars in% s. ", $number,$str);" to replace the specified symbol.

This article operating environment: Windows7 system, PHP7.1 version, Dell G3 computer.

The sprintf () function writes the formatted string to the variable.

The arg1, arg2, + + parameters are inserted at the percent sign (%) symbol in the main string. This function is executed step by step. At the first% symbol, insert arg1, at the second% symbol, insert arg2, and so on.

Note: if the% symbol is more than the arg parameter, you must use a placeholder. Placeholders are located after the% symbol and consist of numbers and "\ $". See example 2.

Hint: related functions: printf (), vprintf (), vsprintf (), fprintf () and vfprintf ()

Example

Replace the percent sign (%) sign with a variable passed as a parameter:

Running result:

There are 2 million cars in Shanghai.

Sprintf syntax:

Sprintf (format,arg1,arg2,arg++)

The above is all the content of the article "how to replace sprintf in php". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Symbols functions parameters articles content variables characters strings percentages percent signs and so on not much examples most instances numbers files methods more formats Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Xiaomi Shulou Tech Info macOS Microsoft