[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

PHP change from days to day text

Posted on 2013-01-25
7
Medium Priority
?
241 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
  • 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
Independent Software Vendors: 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!

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
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 dynamically set the form action using jQuery.
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
Course of the Month17 days, 17 hours left to enroll

830 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