Solved

PHP sprintf

Posted on 2013-01-31
8
284 Views
Last Modified: 2013-01-31
sprintf('"%s" <%s> (%s) [%s]', a, b, c, d);

will not display <%s>

I get "a" (c) [d] not "a" <b> (c) [d]

do I need some escape character or something?
0
Comment
Question by:mosemadl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38840935
Yes, all the options for use in sprintf() are on this page: http://www.php.net/manual/en/function.sprintf.php  To actually display a '%', you need two of them '%%'.
0
 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 38840985
If you're outputting this in HTML you won't see the bit between <> because your page will think it's an HTML tag. View the source of your page and you'll see it, but to render the < and > in HTML you need to use the HTML entities &lt; and &gt;

sprintf('"%s" &lt;%s%gt; (%s) [%s]', a, b, c, d);

Open in new window

0
 
LVL 19

Accepted Solution

by:
Greg Alexander earned 500 total points
ID: 38840994
Just a thought

<?= sprintf('"%s" &lt;%s&gt; (%s) [%s]', a, b, c, d); ?>

Open in new window

0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 19

Expert Comment

by:Greg Alexander
ID: 38841000
Sorry, didn't see that... don't give me points ;)
0
 

Author Comment

by:mosemadl
ID: 38841002
I don't need %

I need <b>

The less than symbol is the issue.
0
 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 38841009
@mosemadl - have you just cross-posted or did you miss my post completely?
0
 

Author Closing Comment

by:mosemadl
ID: 38841037
Sorry galexander07. That's exactly it.
0
 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 38841045
I seem to be having another invisible day :/
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question