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

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