About mathcelebrity

I run 2 websites: www.mathcelebrity.com - A fully automated online tutoring service showing you every single line of math work needed to get to an answer www.barrycode.com - An entire online encyclopedia of MLB baseball stats featuring the stats of Barry Codell

Excel/VBA 301 redirects for htaccess

This Excel/VBA program takes a column list of urls where every odd numbered row is the original url and the next even row below it is the url that represents the redirected URL and writes an .htaccess statement for redirects.  This is helpful if you do not wish to manually write hundreds of redirects.  What this will do is take your large list in column A, put the original url’s in Column C, the redirect url’s in Column D, and your .htaccess 301 redirect statement in Column E:

Option Explicit
Private i As Integer ‘ Represents the current row we are evaluation in Column A
Private j As Integer ‘ Represents the current row for pasting in Column C,D, and E
Private ht_stmt As String  ‘ Represents the current row we are evaluation in Column A
Private Const stacked_rows = 2  ‘ Number of Rows that are stacked, in this case, 2, for both original url and new url

Sub side_by_side()

‘ Initialize Variables
i = 1
j = 0

‘ clear data

‘ Loop Through Each Row until we hit a blank row
Do While Len(Trim(Cells(i, 1))) > 0
j = j + 1

‘ get original url
Cells(i, 1).Select
Cells(j, 3).Select

‘ now get redirect url
Cells(i + 1, 1).Select
Cells(j, 4).Select

‘ .htaccess statement – this will do a standard redirect formula
ht_stmt= “RewriteRule ^” & Replace(Cells(j, 3), ” “, “”) & ” http://www.” & Replace(Cells(j, 4), ” “, “”) & ” [R=301,L]”
Cells(j, 5).Formula = c1

‘ increment i – jump to next row of paired urls
i = i + stacked_rows

End Sub

PHP: Set post/get form submissions to a variable

If you want to take a set of $_POST or $_GET form submissions and set them as variables, you can do this below:

// loop through each POST variable and set $key which is the name of the field to a variable with the value equal to $value which is the form value
foreach ($_POST as $key=>$value){
   $$key = $value;

Therefore, if you have a form of 3 submissons with fields of first_name, last_name, and age with the following values below:

  1. first_name = “John”
  2. last_name = “Doe”
  3. age = 40

You will have pre-set php variables where $first_name = “John”, $last_name = “Doe”, $age = 40. The double dollar sign “$$” makes a variable name value turn into a variable.

Therefore, if you were to print out these variables, in the following script, you would have:

echo $first_name . "\n";
echo $last_name . "\n";
echo $age . "\n";

This would give you: