Oct
14
2008
0

Political Humor

Discovered this via StumbleUpon but the site quit working when I sent it to a friend.  Too much traffic from SU, I'm guessing.

Written by Kevin in: Personal
Sep
13
2008
0

PHP: Autolink Text - Twitter @replies

Update: To prevent any confusion the code highlighter might cause in the post, I added a plain text version of this post here.
I noticed a lot of sites allow user submitted content but prevent autolinking of urls. Some of the most common instances of this are on Twitter sites (much like my own creation: SecretTweet.com). So I threw together a function to autolink urls:

 
<?
$text= 'Hey go to google.com moo http://google.com moo www.google.com moo http://wwww.google.com/404.php moo';
function linkify(&$text)
{
//CONVERT *://.* TO LINK (EG HTTP://KEVINSMITHDESIGNS.COM)
$text = ereg_replace("[a-zA-Z]+://([.]?[a-zA-Z0-9_/-])*", "\\0", $text);
//CONVERT *://*.* TO LINK (EG HTTP://WWW.KEVINSMITHDESIGNS.COM)
$text = ereg_replace("(^| )(www([.]?[a-zA-Z0-9_/-])*)", "\\1\\2", $text);
return $text;
}
echo linkify($text);
?>
 

Would return "Hey go to google.com moo http://google.com moo www.google.com moo http://wwww.google.com/404.php moo".

And since I made this primarily for Twitter, the following will linke @ replies automatically, too:

 
<?
$tweet = "Hey @mozunk! Go check out http://digsby.com -- I think you will like it.";
function twitterify(&$tweet) {
//CONVERT *://.* TO LINK (EG HTTP://KEVINSMITHDESIGNS.COM)
$tweet = ereg_replace("[a-zA-Z]+://([.]?[a-zA-Z0-9_/-])*", "\\0", $tweet);
//CONVERT *://*.* TO LINK (EG HTTP://WWW.KEVINSMITHDESIGNS.COM)
$tweet = ereg_replace("(^| )(www([.]?[a-zA-Z0-9_/-])*)", "\\1\\2", $tweet);
//LINK @USERNAME
$tweet = preg_replace('/([\.|\,|\:|¡|¿|\>|\{|\(]?)@{1}(\w*)([\.|\,|\:|\!|\?|\>|\}|\)]?)\s/i', "$1@$2$3 ", $tweet);return $tweet;
}
echo twitterify(&$tweet);
?>
 

Would return "Hey @mozunk! Go check out http://digsby.com -- I think you will like it."

I'll be implementing this into SecretTweet pretty soon. I haven't decided if I want to autolink URLs or not...maybe just @replies.
---
automatically link urls php
autolink @ replies Twitter automatically link php

Written by Kevin in: PHP
Jul
22
2008
1

Masking PHP via .htaccess

What we're doing: turning the .php extension into .whatever
Why we're doing this: security, seo, or because you want to (then you'll have to answer why for yourself)
How to do this:

In your .htaccess file, we're going to tell apache to parse your choice of a single or multiple .whatevers as php.
So if we wanted to parse .html files as php, we would do something like this:

AddType application/x-httpd-php .html

And if we wanted to parse .bunnyboyfoofoo files as .php:

AddType application/x-httpd-php .bunnyboyfoofoo

And if we wanted to parse .bunnyboyfoofoo, .html, .htm, .py, .kevinsmith, .google files through php:

AddType application/x-httpd-php .bunnyboyfoofoo .html .htm .py .kevinsmith .google

Simple and fun to play with if you're that type of person.

PS:  Sorry it has been so long since my last update...it's summer, I've been enjoying it.

Written by Kevin in: PHP, WebDev
Jun
03
2008
0

301 Permanent Redirect PHP and HTACCESS

Just to compare two of the different ways to effectively do a proper redirect...

PHP:
(old.php)

<?
header ('HTTP/1.1 301 Moved Permanently');
header('Location: http://kevinsmithdesigns.com/new.php');
exit;
?>

.HTACCESS

 
Redirect 301 /old.php http://www.kevinsmithdesigns.com/new.php
 

--------------
I much prefer .htaccess so you can delete old.php and keep track of all redirects via one file (.htaccess).
.htaccess is also probably the safest way to redirect (if you're the SEO conscious type)

Written by Kevin in: PHP, WebDev
May
28
2008
0

Only allow alpha/numeric characters

Strip all symbols and other non a-z, 1-0 characters from a string using the handy-dandy ereg_replace.

<?php
$before= "First !@#$%^&amp;*() Middle _+:?&gt;&lt;|}  Last";
$after= ereg_replace("[^A-Za-z0-9] ", "", $before);
echo $after
?>
 

And the output would be:
"First Middle Last"

---
This is very basic but I see a lot of people going about this the long way around with snippets that are 10-15 lines long (when they only need to be one)...

EDIT!:

Aken pointed out a mistake I made.

I had ereg_replace("[^A-Za-z0-9]", "", $before); when it should be ereg_replace("[^A-Za-z0-9] ", "", $before); (so that spaces are also not allowed). I have corrected the code above. I'm only human :/

Written by Kevin in: PHP
May
15
2008
0

Javascript onfocus-onblur, show-hide table-div

For an example, visit SecretTweet.com and click in the textbox up top--the only textbox on the whole page. The captcha, tags field, language field, and submit button all are hidden until needed by the user.

<html>
<head>
<script type="text/JavaScript">
<!--
function showthetable(theTable)
{
      if (document.getElementById(theTable).style.display == 'none')
      {
            document.getElementById(theTable).style.display = 'block';
      }
}
//-->
</script>
</head>
 
<body>
<textarea name="whatever" cols="55" rows="2" onfocus="showthetable('TABLENAME');return true;"></textarea>
 
<div class="options">
<table border="0" cellpadding="0" cellspacing="0">
<tr id="TABLENAME" style="display: none;">
<td>
Hidden content until onfocus!  Hooray!
  </td>
</table>
</div>
 
Written by Kevin in: Javascript, WebDev
May
07
2008
1

My adwords ads showing in my adsense?

I had thought it was impossible until now:
Here's a screenshot of the ad taken directly from the adwords panel:

And here's a screenshot of the ad showing up in my adsense:

So just to be sure someone hadn't magically used the exact same wording and punctuation as me, I click on my own ad (and another thing: I know google doesn't count your own clicks but do they penalize you?  I'm often curious about where the ads on my site link to but don't want to click and risk google penalizing me somehow) and it takes me to my own site!  WTF?  Doesn't really bother me but this totally shouldn't be happening.

May
01
2008
0

KevinSmithDesigns.com gets a makeover

For the past several months, www.KevinSmithDesigns.com forwarded to /blog (where you are now).  I decided to change that and turn the root directory into a sort of a one-stop resource for everything me.  It's just something quick that I threw together just to get the information out there.  So, check it out; if I'm on any of the social sites you are, follow me/friend me/add me/etc.  :)

Written by Kevin in: Personal
Apr
29
2008
0

Insert Ads Between MySQL Results

If you are pulling information from a mysql database and want to insert either ads (like adsense) or just repeat the headers after every X amount of results, here's my way of doing it:

<?
//connect to the mysql database\
//I always like to define the value of $i as 0 just to keep things straight in my mind.  You can set this to whatever number you want to start counting from
$i=0;
 
//The query -- this is an example from one of my sites.
$result55 = mysql_query("SELECT * FROM table WHERE safe='y' AND language='english' ORDER BY timedate DESC LIMIT 10");
 
//Do the basic while statement
while($row = mysql_fetch_array($result55))
{
//Set the count of $i to plus 1
$i++;
//echo your results
echo $row[id];
//create an if statement and print out an ad on whatever number you like.  Since I limited my query to ten results, I'm going to print an ad after the 5th result (in the middle, obviously).  Note that adsense will only allow you to print three ads on any given page.
if ($i == "5"){ ?>
INSERT ADSENSE CODE HERE
<?
}
?>
 

See a working demo of this at www.SecretTweet.com -- the ad script is repeated after every 3rd ad when the query limits the results to 10. This way I can achieve the maximum number of ads allowed by google while spreading out the ads evenly within the results.

Written by Kevin in: MySQL, PHP, WebDev
Apr
05
2008
0

Powered by WordPress | Aeros Theme | TheBuckmaker.com WordPress Themes