Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

What does Formatting string means in PHP?

Well,this topic is in my syllabus named as “Formatting string”. I looked all over the internet but got no success. I’m not able to understand the meaning of formatting string in php. Can u explain me in detail,can you provide the reference for the topic on internet. Any pdf,blog, anything at all.

1 Answer

Relevance
  • 4 years ago

    Formatting means arranging something is a specific way, like to align with columns or putting a number into currency format (with two digits after the decimal point).

    Without knowing what you are formatting for or to, it's guesswork..

    It could simply be inserting a variable - eg.

    echo "Dear " . $name . ", please find enclosed you bill";

    For building complex formats, you can use sprintf()

    That works in a similar way to the C version - you pass a string containing a format definition, plus the variables you want to include in it.

    http://php.net/manual/en/function.sprintf.php

    Look through the examples in that article for more info.

    Note - They use echo to display the result each time without storing it, but sprintf() just returns the formatted string so you can equally use

    $newstring = sprintf( ...

    and then do something else with the new string.

Still have questions? Get your answers by asking now.