Keep % sign using sprintf()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    Keep % sign using sprintf()

    I use %s as placeholders in a text file and something like
    Code:
    $line = sprintf(fgets($fp),$tc,$tc);
    To read a line.
    So $tc will replace %s in $line.

    But if line contains "charge a 2% surcharge" then $tc also replaces the '%'.

    How do I get round this and leave '%' untouched and only replace '%s'?
    Tried backslash, that doesn't work
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    Solved. It is escaped with a double percent like so '%%'

    Comment

    Working...