I am working on building an online calendar that will, for the moment, simply display what the current date is according to the calendar my circle of friends are creating from scratch, with only some attention paid to the Gregorian Calendar. The code, what I have so far, which is calculating which day of the 5-day week it is, and how the rest of the calendar will be calculated are below. I don't know if what I have coded so far is efficient, or even correct, much less how to continue about figuring out the weeks and months, considering.
<?php
echo "<p><p><p> According to the Gregorian Calender, ";
echo "today is " . date("Y/m/d") . "<br>";
$d1=strtotime("October 18, 2015");
$d2=ceil(($d1-time())/60/60/24);
echo "<p>There are " . $d2 ." days since First Founding, First Sol.<p>";
if ($d2 < "365") { $lastdigit = $d2%10; }
echo "$lastdigit <br>";
if ($lastdigit == "-1") { echo "Today is Mercury."; }
if ($lastdigit == "-2") { echo "Today is Venus."; }
if ($lastdigit == "-3") { echo "Today is Terra."; }
if ($lastdigit == "-4") { echo "Today is Mars."; }
if ($lastdigit == "-5") { echo "Today is Sol."; }
if ($lastdigit == "-6") { echo "Today is Mercury."; }
if ($lastdigit == "-7") { echo "Today is Venus."; }
if ($lastdigit == "-8") { echo "Today is Terra."; }
if ($lastdigit == "-9") { echo "Today is Mars."; }
if ($lastdigit == "0") { echo "Today is Sol."; }
if ($lastdigit == "1") { echo "Today is Mercury."; }
if ($lastdigit == "2") { echo "Today is Venus."; }
if ($lastdigit == "3") { echo "Today is Terra."; }
if ($lastdigit == "4") { echo "Today is Mars."; }
if ($lastdigit == "5") { echo "Today is Sol."; }
if ($lastdigit == "6") { echo "Today is Mercury."; }
if ($lastdigit == "7") { echo "Today is Venus."; }
if ($lastdigit == "8") { echo "Today is Terra."; }
if ($lastdigit == "9") { echo "Today is Mars."; }
$year = date('Y');
$truyear = $year-1;
function is_leapyear_working($truyear) {
if((($truyear%4==0) && ($truyear%100!=0)) || $truyear%400==0) {
return true;
}
return false;
}
if(($d2 == "365") && ($is_leapyear_working == "true")) { echo "Today is Luna."; }
if(($d2 == "365") && ($is_leapyear_working == "false")) { echo "Today is Mars."; }
if ($d2 == "-29") {
echo "<p>First Apprentice, Third Mars<p>";
}
echo "*Year* (st/nd/rd/th) *Month*, *Week* (st/nd/rd) *Day*";
echo "<p> October 18, 2015 according the Gregorian Calender is the First Founding, First Sol. This is, essentially, the \"New Years Day\" of the Ecclesia Chaotica. One week within the Ecclesic Calender is Five days in length, named in order, Sol, Mercury, Venus, Terra, and Mars. There are three weeks in every month, with twenty-four months in a year, called, in order, The Founding, The Apprentice, 3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24. Seventy-three weeks exist in a year, with one of said weeks existing \"outside of time.\" This week is known as the Week of Fotamacus, in honour of him, the God of Chaotic Time. On a Leap Year, every four years,* which are the Second, Sixth, Tenth, Fourteenth, etc. The Week of Fotamacus contains an extra day, dubbed Luna, which falls between Terra and Mars on that Week.<p> *The additional day every Leap Year is due to one cycle around the Sun taking 365.248 days, not a perfect 365, dates must be adjusted to account for this change.";
?>
Related
I have an array with some urls. I want to echo the url which contains the $string. for the moment I only echo "match found". here is the code :
`$string="test";
$people = array(domain.com/test-2.html, "domain.com/2.html", "Glenn", "domain.com/3.html");
if (in_array($string, $people))
{echo "Match found";}
else {echo "Match not found";}`
thanks
So actually you misunderstood how in_array works when you do :
$string="test";
$people = array("domain.com/test-2.html", "domain.com/2.html", "Glenn", "domain.com/3.html");
if (in_array($string, $people)) {
echo "Match found";
}
else {
echo "Match not found";
}
It should always echo "Match not found" if $string is not exactly equals to one of the people value (e.g. $string = "domain.com/test-2.html").
If you want to find a subset of string ("test") in an array the easiest way is to itarate through the values and comparing with strpos :
$string="test";
$people = array("domain.com/test-2.html", "domain.com/2.html", "Glenn", "domain.com/3.html");
$found = false;
foreach ($people as $url) {
if (strpos($url, $string)) {
echo "Match found : " . $url; # Or just : echo $url;
$found = true;
}
}
if (!$found) {
echo "Match not found";
}
Example testable here : http://sandbox.onlinephpfunctions.com/code/b0c39c9493c5731a847d36c4b3ed85686cc21c6b
I have an app where I need to display today, and the next four days on.
$daysOn = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Mon'];
$daysOff = [ 'Sat', 'Sun' ];
$today = date("N", strtotime('today'));
$yesterday = date("N", strtotime('yesterday'));
$daysOnRearranged = array_merge(array_slice($daysOn, $today), array_slice($daysOn, 0, $yesterday));
This is currently showing me:
Monday, Monday, Tuesday, Wednesday, Thursday.
I need to show today, and the next for days on.
Any ideas?
Here I am using the strtotime ability to workout the date using a string like "Today + 1 day". I am also using the character "D" that returns 'A textual representation of a day, three letters'. You can change the "D" to a "l" if you want the full name of the day.
$nextDays = [];
for ($i = 0; $i <= 4; $i++) {
$nextDays[] = date("D", strtotime("today + $i day"));
}
var_dump($nextDays);
To remove weekends:
$nextDays = [];
$daysOff = ["Sat", "Sun"];
$n = 0;
do {
$day = date("D", strtotime("today + $n day"));
if (!in_array($day, $daysOff)) { // Check if the above $day is _not_ in our days off
$nextDays[] = $day;
}
$n ++; // n is just a counter
} while (count($nextDays) <= 4); // When we have four days, exit.
var_dump($nextDays);
On days check condition to be checked inside for loop.
Please have a look into below snippet and running code.
<?php
function pr($arr = [])
{
echo "<pre>";
print_r($arr);
echo "</pre>";
}
$daysOn = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Mon'];
$daysOff = ['Sat', 'Sun'];
$today = date("N", strtotime('today'));
$nextDays = [];
$j = $i = 0;
while($j != 4){ // until it found next 4 working days
$day = date('D', strtotime("today +$i day")); // it will keep checking for next working days
if(in_array($day, $daysOn)){ // will check if incremental day is in on days or not
$nextDays[] = $day; // it will add on days in result array
$j++;
}
$i++;
}
pr($nextDays);die;
Here is working demo.
EDIT
Above snippet is for checking on days.
You can check for OFF Days like below.
while($j != 4){
$day = date('D', strtotime("today +$i day"));
if(!in_array($day, $daysOff)){
$nextDays[] = $day;
$j++;
}
$i++;
}
pr($nextDays);die;
It is my code:
//save user in DB
$email='user1#email.com';
$username='user1';
$password='user1';
echo 'No hashed password='.$password.'<br>';
$user= new User();
$user->email=$email;
$user->username=$username;
$user->password=Yii::$app->getSecurity()->generatePasswordHash($password);
echo 'Hashed password='.$user->password;
echo '<br>';
$user->save();
//check user
$password2 ='user1';
$password2=Yii::$app->getSecurity()->generatePasswordHash($password2); //do hash
echo 'Hashed password2='.$password2;
$check_user=User::find()->where(['email' => $email])->one();
if($check_user) { //if user found
if (Yii::$app->getSecurity()->validatePassword($password2, $check_user->password)) {
echo 'Yes';
} else {
echo 'No';
}
}
I save my data(email,username,password) in DB . And when I want to check my password I always get NO.
How can I solve my problem?
You don't need to generate a new hash when checking the password. Just compare the information ($password2) with your saved hash ($check_user->password).
//check user
$password2 ='user1';
echo 'password2 = ' . $password2 . '<br />';
$check_user=User::find()->where(['email' => $email])->one();
if($check_user) //if user found
{
if (Yii::$app->getSecurity()->validatePassword($password2, $check_user->password)) {
echo 'Yes';
} else {
echo 'No';
}
}
You can find more information in the docs: here and here.
What I'm trying to achieve:
Show either the post tag (without the link) or the title.
If a tag exists, that gets printed if it doesn't, the title gets used.
Issue: I've used get_the_tags() as suggested in the Codex to get the tag without the link and that works, yet it gets the word "Array" printed as a preffix, too.
<?php
if( has_tag() )
{
echo $posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
echo $tag->name . ' ';
}
}
}
else { echo the_title(); };
?>
What am I missing?
You are echo ing $posttags which is an array. If you echo an array it will echo array as output
<?php
if( has_tag() )
{
This is printing Array as prefix ----> echo $posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
echo $tag->name . ' ';
}
}
}
else { echo the_title(); };
?>
Please remove that echo , so your new code will be
<?php
if( has_tag() )
{
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
echo $tag->name . ' ';
}
}
}
else { echo the_title(); };
?>
Hope this helps you
I am trying to count the number of occurrences in an array of cart items in Magento.
There are several items in the array, all with a price field (either $0 and $10)
What I'm looking to do, is to display the count of those items that have a price of 0
I currently have:
$session = Mage::getSingleton('checkout/session');
$items_array = $session->getQuote()->getAllItems();
foreach($items_array as $item) {
if ($item->getPrice() == 0) {
echo 'Item is free';
}
else {
}
}
This simply outputs all the free items. Ideally, I'd like to display just the count of such items.
Could I use something like array_count_values, but limit it to only count those values that are 0?
You can do that with several ways, but having that code the most easy one will be:
$session = Mage::getSingleton('checkout/session');
$items_array = $session->getQuote()->getAllItems();
$freeItems = 0;
foreach($items_array as $item) {
if ($item->getPrice() == 0) {
$freeItems++;
}
}
echo "There are $freeItems free items";
$session = Mage::getSingleton('checkout/session');
$items_array = $session->getQuote()->getAllItems();
$free = 0;
$notfree = 0;
foreach($items_array as $item) {
if ($item->getPrice() == 0) {
echo 'Item is free';
$free++;
}
else {
$notfree++;
}
}
echo 'total free items = ' . $free;
echo 'total nonfree items = ' . $notfree;