?
Solved

PHP change from days to day text

Posted on 2013-01-25
7
Medium Priority
?
237 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
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!

 
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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

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…
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 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…
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

770 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