Jun
27
2010
This is a question I often see and get. “Which one should I use, JavaScript or php?” Well in the end it all boils down to what your doing and how your are expecting it to handle. The biggest key differences between JavaScript and PHP is one runs or renders rather while the page is loading. While the other can do stuff to a page while its loading or after it has loaded.
Both languages are very similar in construct or at least they are in my opinion, and you write code almost the same way. Obviously they have different built in functions, and names for the functions, and they differ here and there. Generally you can almost do anything with JavaScript that you can with PHP and vice versa.
Now comes again the question “Which should I use?”. Well I personally like PHP for a wide array of things and will generally use it over JavaScript when possible however with todays technology always trying to push the bar up and tempting to break the barriers of just how far you can push someones browsers abilities I do favor AJAX which is the use of PHP and JavaScript together. I say “when possible” because there are times where it definitely is not wise to use AJAX. But thats only due to security concerns. But worry not, most applications you will build with AJAX if you use it wisely and properly you wont have much to worry about. Which one day I am sure I will write an article or many about that.
If you want your elements to be flashy and less bandwidth consuming I would suggest using JavaScript where and when possible to handle your pages content and how its loaded, then handled there after. If bandwidth isn’t much of an issue for you which with most hosting providers it isn’t (unless your pushing several thousands of gigs of there bandwidth a month, then you should check the fine print in there contracts). Then handle everything via PHP its a bit more static, pages have to load but if used properly its as secure as it gets, and can run pretty fast as well.
If your interested in going the AJAX route which I highly recommend I would suggest using jQuery. As its the most stable and mature of frameworks out there and has a much larger community of developers to help get answers from if you ever get stuck.
Are you recently starting out with php, javascript, ajax, mysql, or really any web related scripting language? If you are might I suggest to you a site that helped even me learn the basics years upon years ago. http://www.tizag.com they don’t cover everything, but they cover more than just the simple basics and can give you a good footing on any given scripting language.
AJAX ready frameworks that you can choose from in no particular order (obtained from Wikipedia):
jQuery
jQuery UI (used with jQuery)
Prototype
Script.aculo.us (used with prototype)
Ext (now known as Sencha)
MooTools
Yahoo! UI Library
Dojo Toolkit
Quick Question I see with these framworks mostly due to people searching for ready made scripts is can you use more than one framework. Well ultimately it depends which you use. I know jQuery (even combined with UI) you can set it up to allow other frameworks as mentioned on the jQuery site in there article/post about the subject Using jQuery with Other Libraries however outside of that I cant really vouch for the other libraries and there support on the subject as I prefer jQuery and use that over the rest when ever possible (unless I am working on a clients site and they have something different from jQuery)
no comments | tags: ajax, javascript, jquery, php | posted in Coding
Jun
23
2010
Have a need for a quick random string of any given length but want to limit it to a-z 0-9. Then this would be ideal for you, I really can’t think of any real world use for this. Well no thats wrong, you can use it as a random password generator. Or something to the effect of that.
<?php
function genRandomString($howbig) {
$length = $howbig;
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
$string = '';
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters))];
}
return $string;
}
echo "<strong>5 char string:</strong> ". genRandomString('5') ."<br />";
echo "<strong>10 char string:</strong> ".genRandomString('10')."<br />";
echo "<strong>15 char string:</strong> ".genRandomString('15')."<br />";
echo "<strong>20 char string:</strong> ".genRandomString('20')."<br />";
echo "<strong>50 char string:</strong> ".genRandomString('50')."<br />";
?>
Example of use:
5 char string: h7zl3
10 char string: gj5kgx2pdx
15 char string: hilnh5lx2onzfd
20 char string: cvrzz9vzqf5gqjoo19
50 char string: b6gjrlgdq70yyq2tg2cbrgz4cnvtsqbj3ay0r17c1vbiorvx
no comments | tags: php, php alpha-numeric, php random string | posted in Coding, PHP
Jun
22
2010
Every now and again on my projects I come into a spot where I have limited room to display any given amount of text that is generated and updated dynamically. Example I have a length of text thats 400 some odd characters long. I only have room for 120 characters. “So what do I do?” If your asking yourself that question then I have an answer for you, keep in mind not THE answer as there are better solutions out there that will trim truncate any given string down to the number you want but leaving full words in tact at the end rather then cut them off mid word. This function I will show you here that I made for myself a while back is expandable to do such things however I haven’t ran into the need or desire to expand it as such myself as it works for what I use it for without problem.
<?php function ShortenText($text, $chars) {
$chars = $chars;
$text = $text."";
$countchars = strlen($text);
if($countchars > $chars) {
$text = substr($text,0,$chars);
$text = substr($text,0,strrpos($text,' '));
$text = $text."...";
}
return $text;
}
$myText = "Welcome to Monkey Tooth Productions.";
echo ShortenText($myText, 20);
?>
Translates to:
Welcome to Monkey…
It automatically appends the “…” to the string so try to remember that if you need 20 max you should set it to 17 however you can change that or remove it even if you like.
Well as with any code I throw up here on the site, if you expand this and improve it let me know. I’d be happy to see what you guys do with it.
no comments | tags: php, php shorten, php truncate | posted in Coding, PHP
Jun
22
2010
I have seen this done a hundred and one ways (figuratively speaking of course). However each way I have seen it there was always the occasion something would come up short, and the IP variable would come up undefined or empty. So it eventually lead me to having to tailor my own solution to obtain either my IP or a users IP depending on what my cause is.
Example: Your IP is: 38.107.191.105
How was this obtained? Through a rather simple process of elimination. Since there are multiple ways to get an IP address, yet not a single one of them works every time dependent on the user side of things. So what I have done is made a little function to try diffrent methods and then return the result to me. See the code below. It’s that simple. Although I am sure some of you are likely able to expand on this in a multitude of ways i’d be happy to see what come up with.
<?php
function getRealIpAddr(){
if(!empty($_SERVER['HTTP_CLIENT_IP'])){$ip=$_SERVER['HTTP_CLIENT_IP'];}
elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];}
else{$ip=$_SERVER['REMOTE_ADDR'];}
return $ip;
}
echo "Example: Your IP is: ".getRealIpAddr();
?>
no comments | tags: ip, ip address, my ip, php, user ip | posted in Coding, PHP
Jun
22
2010
Need to find your domain name for a script? Maybe you want to ensure something thats going to run is being run on your site and your site alone. In concept for example trying to protect your script from XSS attacks, say in a case where your using AJAX to POST/GET JSON requests (but this is only a small example of why you might want to implement something like this).
<?php
$mydomain = $_SERVER['HTTP_HOST'];
$mydomain = str_replace('www.', '', $mydomain);
if($mydomain == "your-domain-name.com"){
}else{
}
?>
Now some people will most likely argue that you should use
$_SERVER['SERVER_NAME']
instead of
$_SERVER['HTTP_HOST']
And this is plausible as they do pretty much the same exact thing. However the key difference is how one reads off the server versus the other, I would go in to the differences but Chris Shiflett puts it together in a nice summary in his article SERVER_NAME Versus HTTP_HOST and backs it up with various tests and other articles he has found on the subject.
no comments | tags: domain name, php | posted in Coding, PHP
Jun
19
2010
“Giving the perfect gift of Fun LOVING Memories.
Take the time to save your cherished memories on DVD. Forgotten old films and home movies that you haven’t seen for years, can now be watched and enjoyed to a whole new generation. Grand Dad at Christmas or mom holding the new baby all brought back to relive once again. Old videotapes or movies films are not a problem to transfer at Steve Sattler Films.” Continue reading
no comments | posted in Portfolio
Jun
19
2010
“Today there is a collision between old and new media. Steve Sattler Films offers an array of Media Content Solutions.
Video is replacing signage, training, manuals, and marketing. We have the means and the expert skills to produce quality and affordable video and audio solutions for your business.
Steve Sattler is an Emmy Award winning Director and Filmmaker. He has 25 years experience in Broadcast TV, Film, Documentary and Commercial Production and is an experienced cameraman, editor and producer. Steve Sattler Films is a full service film and video production facility, located in Connecticut about 90 minutes from north east of New York City or South West of Boston.” Continue reading
no comments | posted in Portfolio
Jun
19
2010
“THE BAR & WINE SHOW is the Premier Trade Event on the East Coast…Bar None!!
The Industry Marketplace for new & classic products & services.
The Bar & Wine Show is located in the heart of New York City. Where there are more establishments that serve and sell spirits beer and wine, within 2 hours of the Jacob Javits Convention Center, than any other place on earth! New York City also has the heaviest concentration of bars, clubs, and restaurants in the world. Which gives you a formidable combination for success! The Bar & Wine Show means Business and is the only Trade Show specifically for Professionals representing the Bar, Nightclub, Restaurant, and Liquor Store Industry.” Continue reading
no comments | posted in Portfolio
Jun
19
2010
“For the past 17 years, the EXPO has helped to present the finest products & services available to the GLBT consumer. Starting in 1993, the EXPO has generated over $80,000,000 of dollars spent within the Greater Tri-State area. This includes the GLBT friendly companies from every industry, both large and small, Fortune 1000 and Gay-owned companies. They have all discovered the GLBT Community is affluent, brand-loyal, well educated and business minded. It is the truest of definition of “THE PERFECT NICHE MARKET”.” Continue reading
no comments | posted in Portfolio
Jun
9
2010
Well I take it your looking you are looking for a place to expand your mafia in the game Mafia Wars by Zynga on Facebook. Well you have found the right spot. I have however moved it to its own location. Mafia Monkey Bulk Email List.
When you click on the link above you will be brought to a page that looks sort of (maybe unless I change it later) like this:
Continue reading
13 comments | posted in Portfolio