Solved

PHP sprintf

Posted on 2013-01-31
8
277 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
  • 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 18

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
 
LVL 18

Expert Comment

by:Greg Alexander
ID: 38841000
Sorry, didn't see that... don't give me points ;)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now