?
Solved

PHP change from days to day text

Posted on 2013-01-25
7
Medium Priority
?
238 Views
Last Modified: 2013-01-25
Hi guys,

I have a variable called $remind_days I'm printing on a page.

When the variable is 1 I want the sentence I'm printing to read 1 day and when it's more than one day to read days (e.g. 3 days).

Here's the code for the line:

You have an active reminder for every ' . $remind_days.  ' days of inactivity

Open in new window

0
Comment
Question by:TLN_CANADA
[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
  • 4
  • 3
7 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 2000 total points
ID: 38820957
Try:
You have an active reminder for every ' . $remind_days.  ' day' . ((1 == $remind_days) ? '' : 's') . ' of inactivity

Open in new window

0
 

Author Closing Comment

by:TLN_CANADA
ID: 38821003
Thanks so much Robert!
0
 

Author Comment

by:TLN_CANADA
ID: 38821008
I also need to alter it slightly to do the same on this line, I'm not quite sure how to do this though.

$message = "Greetings $pieces[0], \n\n As you'd asked us before, we're reminding you that you have not logged any exercise in $days days.

Open in new window

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38821035
Since you're using double quotes there it should be:
$message = "Greetings $pieces[0], \n\n As you'd asked us before, we're reminding you that you have not logged any exercise in $days day" . ((1 == $days) ? '' : 's') . ".

Open in new window

I assume something else is following that otherwise don't forget to end the line with:
";

Open in new window

0
 

Author Comment

by:TLN_CANADA
ID: 38821047
Yes, that's correct. I assume this is correct now? It's a cron script so I can't check it.

$message = "Greetings $pieces[0], \n\n As you'd asked us before, we're reminding you that you have not logged any exercise in $days day" . ((1 == $days) ? '' : 's') . ". \n\n Hope to see you soon! \n\n";

Open in new window

0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38821077
It looks ok but you should never assume. Of course you can test, just take the relevant pieces of the code and hard-code some values. Something like:
$username = "Robert Schutt";
$pieces = explode(" ", $username);
$days = 1;
$message = "Greetings $pieces[0], \n\n As you'd asked us before, we're reminding you that you have not logged any exercise in $days day" . ((1 == $days) ? '' : 's') . ". \n\n Hope to see you soon! \n\n";
echo $message;

Open in new window

and then test it with $days = 1 (the value being tested) and one or more other values.
0
 

Author Comment

by:TLN_CANADA
ID: 38821085
Works like a charm! Thank you very much mate!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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 a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

650 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