» Smart Phones, Web Design, Google or whatever
Web Design
Web Design, likley a lot about what you should and should not do in web design from a coding and design standpoint as relating to usability or “web site common sense”.
Using PHP to convert a string to lowercase
Jul 15th
At times you may need to change a string to all lowercase letters, here is the way to do that (2 samples including one practical application):
SYNTAX: string strtolower (string $mystring);
$myLowercaseString = strtolower ($mystring);
As with all PHP, test to make sure you’ve implemented correctly. Comments, questions or suggestions? Please leave a comment.
Using PHP to redirect to another page
Jun 18th
Using PHP to redirect to another page is a common task, especially when you are working with email forms. Fill the form out, process it, then redirect to a “thank you” page:
<?php
header( “Location: http://www.example.com” ) ;
exit;
?>
You can also use variables for the URL like so:
<?php
$destURL = “http://www.example.com”;
header( “Location: ” . $destURL ) ;
exit;
?>
NOTE: The code above has to be processed before any HTML headers, so it needs to be placed above ANY HTML code.
NOTE 2: Watch the code above, depending upon my current CSS in my current theme the single quotes or even double quote may change to fancy quotes which will need to be edited if you cut-n-paste the code.
MORE info available on PHP.net’s header manual page
Using PHP to grab the Referer
Jun 18th
You can use PHP to track how someone got to a specific page by grabbing the referring page, called the referer. Use this code to get that info:
<?php
$myReferer = $_SERVER['HTTP_REFERER'];
?>
NOTE: Watch the code above, depending upon my current CSS in my current theme the single quotes or even double quote may change to fancy quotes which will need to be edited if you cut-n-paste the code.
MORE info available on PHP.net’s $_SERVER manual page
CSS: All Caps
Jun 16th
Need to have all caps and CSS seems the best way to do it? Maybe you don’t want to re-code an entire menu (like me today!).
Use this:
.allcaps {text-transform: uppercase;}
… and there’s no need to re-type a bunch of text links.
MORE INFO
PHP: Find Server and Domain Paths
Apr 27th
For building sites that can more easily be moved from one server to another, and allows simpler updating of common information like email address and phone number of the client.
Here’s some PHP to generate paths: both server paths and domain paths good for use in all sorts of ways for include and require statements.
<?
// for INCLUDE statements – this is the local server path
$urlPATH = “http://” . $_SERVER['SERVER_NAME'];
$srvPATH = $_SERVER['DOCUMENT_ROOT'];
include ($srvPATH.”/config-settings.php”);
?>
More later.
PHP Do Until – Do While
Apr 16th
The PHP Do While, just a quick post so I can find this later without Googling…
<?
$i = 0;
do
{
// do something
}
while ($i > 0);
i++;
?>
MORE
PHP Do While on PHP.net
Redirecting Dynamic URL to Static using .htaccess
Mar 11th
I (finally) found some documentation today on how to redirect a dynamic URL to a static URL. For example changing www.example.com/page.php?article=22 to www.example.com/apples-and-oranges.php
This is your .htaccess file entry to do the above redirection, of course the RewriteEngine on command is only needed once before the first redirect… This will work for ONE variable pair
RewriteEngine on
RewriteCond %{QUERY_STRING} ^article=22$
RewriteRule ^page\.php$ http://www.example.com/apples-and-oranges.php? [R=301,L]
Now if you need to redirect a dynamic URL with more than one name/valu pair like this:
www.example.com/page.php?widget=cellphone22&color=red
You will need to use the following code:
RewriteEngine on
RewriteCond %{QUERY_STRING} [&]?widget=cellphone22[&]?
RewriteRule ^page\.php$ www.example.com/cellphone22.php? [R=301,L]
In this last example, &color=22 is ignored.
Resources for this post:
http://www.webmasterworld.com/apache/3365089.htm
http://www.seoverflow.com/blog/seo/setting-up-301-redirects-for-dynamic-urls/
PHP Local Time – Your timezone
Dec 11th
UPDATE: After a comment from a visitor I re-checked my code, did some testing and added the echo statement with formatted time, and improved the comments about how to check for the correct value of $offset. Also, note I have not used this code for a year yet so I do not know if daylight savings has been taken into account.
PHP code to get time in YOUR timezone…
<?
$mydatetime = time ();
$offset= 0; // offset in # of hours from desired location
// check the time displayed using $offset = 0 and adjust
// the offset accordingly
$mydatetime = $mydatetime + ($offset * 60 * 60);
echo date (“g:i A”, $mydatetime);?>
Check the PHP Time manual page for formatting the time. This code has only been tested on two implementations. When I wanted to display the local time for a website’s “offical time” I couldn’t find any simple explanations online.
Comments/feedback are invited.