Showing posts with tag: php
Posted September 26, 2011 by Nick Vogt in Programming
If your site accepts any form of user input, it's a good idea to understand the differences in newline characters between platforms and how to handle them (and it's just good to know in general). Say your site is running on a Unix host and receives comments or posts from Windows clients. Any HTML textarea form input sent from the Windows clients will contain newline characters that do not match those native to the Unix host. Likewise, if your site runs on a Windows host, the occasional Linux or Mac user will be sending non-native newline characters as well.

Here are the newline characters that each major system uses:

PlatformLine Break
Windows\r\n (Carriage Return & Line Feed)
Unix/Linux/MacOS X\n (Line Feed)
MacOS 9 and earlier\r (Carriage Return)


Continue reading...
Posted May 17, 2011 by Nick Vogt in Programming
JSON stands for JavaScript Object Notation. It is a widely-used model for transferring variable data as text, and is often used in combination with AJAX to create the basis for highly-interactive, portable, and modular websites (Facebook, Twitter, etc).

If you are familiar with JavaScript objects, then you already know JSON! If you aren't, it is very easy to learn. A JavaScript object is just like an object in ActionScript 3 or an associative array in PHP, just with slightly different syntax.

Here is the basic syntax for JSON. This object contains two strings, an array, and an object:

{
   "one": "A Number",
   "hello": "world",
   "myarray": [
      "orange", 
      "apple", 
      "banana"
   ],
   "myobject": {
      "library": "books",
      "bar": "alcohol"
   }
}


Continue reading...
Posted May 12, 2011 by Nick Vogt in Programming
In a nutshell, AJAX allows you to update parts of a page with server-side content using JavaScript, without reloading the whole page. AJAX is not a new language, it's just a method for using JavaScript to achieve this functionality.

To use AJAX you will need to know a bit of JavaScript and (for this example) PHP, and have a server that can parse PHP. If you don't have this, you can download Apache server and PHP for free from their respective websites (follow my guide on setting up Apache, MySQL, and PHP on Windows).

Before diving into AJAX, first take a look at this example:

<html>
<head>
<script type="text/javascript">
function hello()
{
   document.getElementById('content').innerHTML = 'Hello World!';
}
</script>
</head>
<body>

<input type="button" value="Click Me" onclick="hello();">

<div id="content">Nothing here yet.</div>

</body>
</html>


Continue reading...
Posted February 22, 2011 by Nick Vogt in Programming
MySQL's full-text search allows you to quickly search a table for single or multiple keywords from multiple columns. It does this by using an index on the columns that you want to search. There are a few limitations that you should know of. Indexed columns can only be CHAR, VARCHAR, or TEXT, MySQL does not by default index words that are less than 4 characters, and any word that appears in over 50% of rows is excluded from the results. There are also stop words.

With that out of the way, let's start. First you need to create the index. The index should be on the columns that you will be searching. For example, to index the title, body, and tags column, run a MySQL query like this (for the table "posts"):

ALTER TABLE posts ADD FULLTEXT(title, body, tags);

You can also create the index using phpMyAdmin. To do so, browse to the table, click on Structure to edit it, and towards the bottom you'll see something like "Create an index".




Continue reading...
Posted February 15, 2011 by Nick Vogt in Programming
Many of the sites I build require an image thumbnailer, so that users can upload an image and it will automatically be thumbnailed. I decided to write a function that I could incorporate into these sites quickly and easily. This function takes a number of arguments, and will create any number of thumbnails in any sizes, and also has the option of moving the original, unedited file into a folder. It handles jpg, png, and gif, and creates jpg thumbnails.

Download it here, name it and put it somewhere. Use php "include" or "require" where it is needed, then call the createthumbs function, which takes four arguments:

The first argument is the $_FILES[] variable that points to the file that was uploaded.

The second argument is the filename of the image.

The third argument is an array that contains the different sizes and locations to save the images. It is formatted like so: array('imgdir/thumb' => array(360,240), 'imgdir/large' => array(800,600)). Each key in the main array is the image folder, and each value is an array that contains the width and height. You can have as many as you want.

The fourth argument is optional, and is a string that points to the directory you want the original image to be saved in, if you want it saved.


Continue reading...
Posted September 16, 2010 by Nick Vogt in Programming
Having a code block allows you to display code without it being interpreted as HTML or parsed on the server. Code blocks are used extensively on programming-related forums and web sites so users can show other users the code they use. Here is a simple code block:

<html>
<head>
<title>H3XED!</title>
<meta name="description" content="My Blog.">
<meta name="keywords" content="gaming, stuff">
</head>
<body>
Hello world!
</body>
<html>

You can also get fancy and style your code:


Continue reading...
Posted March 12, 2010 by Nick Vogt in Programming
See this post for a better search engine implementation.
-------

This guide / tutorial is a follow up to my previous PHP MySQL search engine guide. In this guide, we will be implementing a couple of useful search features into our search engine. The features we will be adding are a checkbox that will determine if we want to match case or not, and the ability to use an asterisk (*) to search for partial words

Continue reading...
Posted March 11, 2010 by Nick Vogt in Programming
See this post for a better search engine implementation.
-------

This guide / tutorial will show you how to write a PHP search engine that effectively searches through a MySQL database. Many sites have search engines that link to Google search results. This method is usually ok, as Google's search algorithms are good, but for sites with database-driven content, a custom-built search engine is often times better. They aren't difficult to create, it just involves a MySQL query and some array manipulation.

Continue reading...
Posted February 22, 2010 by Nick Vogt in Programming
See my updated beginner guide here.

AJAX (asynchronous JavaScript and XML) is a method for using JavaScript and server-side programming languages to access the server and update specific elements without having to reload the current page.

To learn AJAX we will use a very simple example that utilizes JavaScript, PHP, and MySQL to update a DIV element on a page with dynamic content from the MySQL database. We will use two PHP files for this example:

Continue reading...
Posted February 19, 2010 by Nick Vogt in Programming
If you've been developing in ASP 3.0 (classic ASP) you may be used to calling the response.redirect() function whenever you need to redirect a user to a different page. You could call this function anywhere in the page, which was convenient. Now that you're all grown up and using PHP, you may be a little confused about how to redirect in PHP. In PHP, you redirect using the header() function and it must be called before any HTML. Like so:

<?php
header('Location: index.php');
exit;
?>
<html>
<body>
Hello world!
</body>
</html>

The function is straightforward. Simply change index.php with the location you want. The exit function is also needed as it terminates the rest of the script from running.


Continue reading...
Features
Free Web MP3 PlayerComputer Build GuidePHP Beginner Tutorials
Post Series
ActionScript 3 TutorialsHard Drive Cost Charts
Popular Tags
actionscriptajaxcall of dutycrysisebayfacebookgooglejavascriptminecraftneweggphprageskyrimtutorialyoutube


H3XED © 2012 Nick Vogt | Web Design
Wednesday, February 22, 2012 | Privacy Policy | Disclosure Policy | Contact