Jared
Members-
Content Count
38 -
Joined
-
Last visited
Everything posted by Jared
-
In my days of calendar making I've encountered a few minor inconveniences. When you try to make a calendar, you have to find a few specific things: (1) the first day of the month, (2) how many days are in the month, and (3) what today's date is. The second and third ones are easy to find. Before we start making a calendar, though, let's set some ground rules: define ('TS', time ()); Now we can find (2) and (3) from above: $total_days = (int) date ('t', TS);$todays_date = (int) date ('j', TS); Now (1) is a different issue altogether. The way that I originally used to do it was to subtract a given date from the day of the week of that date and then add 1 and add 7 until you have a number between 0 and 6, inclusive. $first_day = date ('w', TS) - date ('d', TS) + 1;while ($first_day < 0) $first_day += 7; The reason for having a while statement to do what could simply be done with the modulo operator (%) is because PHP is a little bit annoying when it comes to modulo. It seems that me that when you calculate a modulo, you should always have a positive number. So: 35 % 7 = 030 % 7 = 2-35 % 7 = 0-30 % 7 = 5 However, PHP does not see eye to eye with me on this one. Unfortunately, this is what PHP tells you: 35 % 7 = 030 % 7 = 2-35 % 7 = 0-30 % 7 = [b]-2[/b] Now the tricky part here is that while 5 and -2 may be congruent modulo 7, they are not equal if you're not talking in modulo terms. So if we want to use modulo instead of the while statement and the 20th of April is on a Sunday then we have this: $first_day = (date ('w', TS) - date ('d', TS) + 1) % 7;$first_day = (0 - 20 + 1) % 7;$first_day = -19 % 7;$first_day = -5; So we don't get a sensible value, as any sensible value would be positive. And the difficult part here is that you are not sure whether or not this value is negative. So if you want to use modulo, you still need an IF statement to decide whether or not to correct the negative. But I finally came up with a better solution! Since the day of the week will never be less than 0 and the given date will never be greater than 31, the "potentially negative number" will never be less than 0 - 31 + 1 = -30. The next positive multiple of 7 larger than 30 is 35, so if we add 35 to this number it will not affect the modulo answer and it will ensure that the number is always positive. So our equation changes from 0 - 31 + 1 to 0 - 31 + 1 + 35 = 0 - 31 + 36. So then now we can use modulo and not have to worry about IF statements or WHILE statement! $first_day = (date ('w', TS) - date ('d', TS) + 36) % 7; It's not like it's a particularly genius idea, but it certainly simplifies the calculation. And save a potential 4 while statements. So then if we want to turn this information into a calendar, here is a very simple script: <?phpdefine ('TS', time ());$first_day = (date ('w', TS) - date ('d', TS) + 36) % 7;$total_days = (int) date ('t', TS);$todays_date = (int) date ('j, TS);echo '<table>' . "\r\n";echo '<tr>' . "\r\n";echo '<td align="center" colspan="7">' . date ('F Y', TS) . '</td>' . "\r\n";echo '</tr>' . "\r\n";echo '<tr>' . "\r\n";echo '<td align="center">S</td>' . "\r\n";echo '<td align="center">M</td>' . "\r\n";echo '<td align="center">T</td>' . "\r\n";echo '<td align="center">W</td>' . "\r\n";echo '<td align="center">T</td>' . "\r\n";echo '<td align="center">F</td>' . "\r\n";echo '<td align="center">S</td>' . "\r\n";echo '</tr>' . "\r\n";for ($i = 0; $i < 6; $i++) { echo '<tr>' . "\r\n"; for ($j = 0; $j < 7; $j++) { echo '<td align="center">' . (($t = $i * 7 + $j + 1 - $first_day) >= 1 && $t <= $total_days ? ($t == $todays_date ? '<b>' . $t . '</b>' : $t) : ' ') . '</td>' . "\r\n"; } echo '</tr>' . "\r\n";}echo '</table>' . "\r\n";?> So there you have it! Any questions? Comments? Please post and let me know!
-
Is this what you're looking for? <body style="margin: 32pt;"><center style="font-family: tahoma; font-size: 8pt;"><script language="JavaScript">TargetDate = "12/31/2020 5:00 AM";BackColor = "white";ForeColor = "midnightblue";CountActive = true;CountStepper = -1;LeadingZero = true;DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds";FinishMessage = "It is finally here!";</script><script language="JavaScript" src="http://scripts.hashemian.com/js/countdown.js"></script></center></body>
-
Live Id. How Can I Intergrate? I need to use Live ID in my web application
Jared replied to PureHeart's topic in Programming
Well there may not be a how-to that teaches exactly what you need to know, but I found on that very same page this link: https://dev.onedrive.com/sdks.htm It seems to have some useful resources such as a forum, an SDK, and the "API Poster." But usually Microsoft is kind of stand-offish with their documentation, so unless you can find a third party one out there somewhere, the forum would probably be the best resource. Hope this helps, Jared -
Actually if you're looking for amazing functionality I would check out some of the sites that host counters for you... my favourite is likely Bravenet. Not quite sure how far their functionality goes, but they certainly have a lot of choices when it comes to setting your counter up and displaying it.
-
Preventing Browsing Directories if it is a Subdomain..
Jared replied to Quatrux's topic in Programming
This would likely work fine for small hosts, but if you were starting something like Xisto where you could potentially have tens of thousands of subdomains, this solution would not be practical. My favourite solution to this problem is just relocate the subdomain directories. Document root: /www/username/domain.com: /www/username/domain.com/sub1.domain.com: /www/username/sub1.domain.com/sub2.domain.com: /www/username/sub2.domain.com/... Again, some hosts might not let you set the document root of the main domain (but rather point it to your document root) but if that is the case then you're probably not hosting that many subdomains. So which solution you use depends on your needs. Also... question... What would happen if the person who owned example.domain.com created a folder in their root directory called example? When http://forums.xisto.com/no_longer_exists/ or http://forums.xisto.com/no_longer_exists/ (as the case may be) would it not just redirect back to the root domain? -
This is driving me mad too haha... But then again it's a bit tricky without actually having the database. The only thing I can think of right now is that there's an empty query somewhere. A query may be empty is syntax is off, rather than undefined.. This would cause the die() not to execute. So then perhaps mysql_result is thrown off and then it calls an error slightly after (PHP sometimes calls an error a few lines after the error has actually occured.. at least for me haha).- Jared
-
I'm afraid I can't give you a very clear answer, but htmlspecialchars () would effectively remove anything that could be maliciously (bad choice of word) interpreted in HTML.. So as far as security goes, you're fine. Now we just have to worry about formatting. Essentially, the <pre> tag would make text appear exactly as shown, so we just have to think about what the <pre> tag really does. So it turns out the <pre> tag simply treats newlines and spaces as they are entered. So we just have to format those. nl2br () would take care of the newlines, but the spaces are still unaccounted for. But this may be a simple matter... we wouldn't be able to use a regular expression to replace multiple spaces with if there were tags in the midst--since <a href=""> is the same as <a href=""> and not <a href="">--HOWEVER there are no tags here! Text is being displayed exactly as it is. So we have a regular expression: (\s{2,}) Also... I just remembered... we have to watch out for tabs, too. Tabs (unfortunately) cannot be forced to print as a space can with , but you can use to make it slightly more html-friendly. So my final answer would be: <?php$text = 'your mysql variable';$text = htmlspecialchars ($text);$text = preg_replace_callback ('/(\x20{2,})/', create_function ('$matches', '$list = false; for ($i = 0; $i < strlen ($matches[1]); $i++) $list .= \' \'; return $lsit;'), $text);$text = preg_replace_callback ('/(\x09{2,})/', create_function ('$matches', '$list = false; for ($i = 0; $i < strlen ($matches[1]); $i++) $list .= \' \'; return $list;'), $text);$text = nl2br ($text);echo $text;?> That would work. My create_function is slightly sloppy, so you might want to fix that up if you can find a better way haha.. P.S. The only way you could "make tabs format" is if you decided to replace each tab with, say, 5 spaces. It's not the same idea as the tab (since a tab has variable space) but it's close. That would be this: $text = preg_replace_callback ('/(\x09{2,})/', create_function ('$matches', '$list = false; for ($i = 0; $i < 5 * strlen ($matches[1]); $i++) $list .= \' \'; return $list;'), $text); Hope this helps!!! - Jared
-
Desperate With Help On Php And Imap To Read Emails. Please!
Jared replied to shadow-x's topic in Programming
I actually copy-and-pasted your code directly into a new file on my home server and replaced the user and pass variables with my own and replaced localhost with my mail server's name and it connected perfectly and correctly reported the number of emails in my inbox... Also, the echo $connect; also returns Resource id #2 as well, which is interesting. I'm not sure that the id number really matters, it probably depends on how PHP is installed or what version you have... I'm not sure. But as a result of this, I would have to think that there is a problem with your mail server... Either there's a connection problem--does your server require authentication?--or there's an error in the build, or something. Have you checked the troubleshooting manual? Because I'm led to believe that it's a problem with the mail server rather than PHP... Hope this helps, Jared -
Not going to lie, I've never heard of it. And I'm probably not the only one. But it looks like it's worth a look!
-
What did you pick? I'm not familiar with the PHP installer, but surely you didn't pick PWS or IIS? If you have WAMP, that means you're using Apache. W - Windows A - Apache M - MySQL P - PHP If there was no Apache option, then you can't use the installer (or you just have to update your .conf files manually)... at least that's how it used to be. Last time I used the installer was back in the PHP3/early-PHP4 days... - Jared
-
Hey folks! I've got a question... I'm looking at developing a website that generates its content based on an XML feed from an API call. My question to you is, what's more efficient, constantly making API calls and downloading a lot of information, or saving calls to a database and recalling them when needed?See, I'm not sure how many requests will be served NOR am I sure how often the API sources will be updated... is there a place where a line gets crossed and says a database would be better than constant API calls?Thanks,Jared