This is not exactly API related thing, just a function that allows to create your content suggestions to other sites like twitter, google buzz and facebook. Of course by modifying you can add more sites.
It is also recommended to use url shortening service, because sites like twitter has limited symbols.
So code for...
Comments Read more
This piece of code allows you to force users to download multiple files one by one using javascript. It can be used to simply download files or use it combination with PHP force download. Although javascript opens file in new window, thus forcing open/save dialog box, it might not work in all browsers. So you may want to modify it to link file...
Comments Read more
phpFreeChat is one of the best, because of it's customization options and easy integration with site authentication. You can download it here:http://www.phpfreechat.net/.
The version I used is 1.2 and it has automatic installation PHP file, which I recommend to use.
After installation to use this chat with your site...
Comments Read more
Here is the code, that gives you list of all $_SERVER variables and values:
<?php
echo "<table border='1'>";
foreach($_SERVER as $key => $value)
{
echo "<tr><td style='width:100px;'>" .$key ."</td>";
echo "<td style='width:600px;'>".$value."</td></tr>";
}
echo...
Comments Read more
There are lot of different ways how to initialize array in php. Which one is the best? which is the slowest?
Here are some test results:
<?php
//average result: 0.0044 seconds.
for ($i=0;$i<1001;$i++)
{
$a=array("1","2","3","4","5","6","7");
}
//average result: 0.0021 seconds
for ($i=0;$i<1001;$i++)
{
...
Comments Read more
To do this you will need http://webcodingeasy.com/jquery.js library. So for example in one select element we have two parents, each of them has their own children. We want to display children of selected parent in second select element.
So here is a code for select elements:
<select name='parent' id='parent'...
Comments Read more
This function generates random string up to 32 characters length. It can be used to generate text for captchas or generate random password, when user wants to reset is. It takes length of string to generate as parameter:
<?php
function random_string($length = 0)
{
$random = md5(uniqid(rand(), true));
if ($length >...
Comments Read more
Here is a code example how to update countdown on your website every second. You only need to setup start time.
<p>
<span id='years'></span><span id='y'> years </span>
<span id='months'></span><span id='m'> months </span>
<span id='days'></span><span id='d'> days...
Comments Read more
Here is a function to get book title and author based on book's ISBN number. To use this function you will have to register here: http://isbndb.com to get your API key.
After that you can use this function to ge xml data about the book:
<?php
//fucntion to get book title and author based on ISBN number
function...
Comments Read more
Browsers usually have limit on how many files they can download from one domain simultaneously, so in theory, if you files would be on different domains or sub-domains, they will be downloaded simultaneously, thus loading your page faster. Of course you don't want to create different sub-domains for different files and you don't have...
Comments Read more
There are couple things you need to keep in mind, when dealing with sessions. Of course you can store session data in database with your own identifiers and prevent it from being hijacked. But if you choose to use $_SESSION variables, then first thing to keep in mind, that all sessions are saved in files in plain text, so it is possible to view...
Comments Read more
To create a sortable list you will need http://webcodingeasy.com/js/mootools.js javascript library in your <head> tags.
Then you can use this simple list (attribute alt is the identifier)
<ul id='list'>
<li alt='1'>item1</li>
<li alt='2'>item2</li>
<li alt='3'>item3</li>
<li...
Comments Read more
Function that not only reverses string, but reverses each line of string, so it looks exactly like in mirror. Check here for example: http://mirrored-text.co.cc/
function rorrim()
{
reversed = document.getElementById('text').value;
revertext = reversed.split("");
revertext = revertext.reverse();
reversed =...
Comments Read more
It is not actually API, it's just retrieving atom feed of your unread emails. You can then modify this function to parse feed to match your needs:
<?php
//fucntion to get unread emails taking username and password as parametes
function check_email($username, $password)
{
//url to connect to
$url =...
Comments Read more
This function creates thumbnails for images. It takes image path with file name, thumbnail width, thumbnail height and path where to save thumbnail as parameters.
<?php
function thumb($path, $width = 120, $height = 100, $dest = "./thumbs")
{
//getting image sizes
$img_sizes = getimagesize($path);
//sizes for calculation
...
Comments Read more
This PHP function is to resize image in proportion between old size and new specified size without loosing much of image quality.
It determines if image is landscape oriented, portrait or square and resizes image accordingly.
Function takes path to image, new width and new height as parameters.
<?php
function...
Comments Read more
This is function to check if there are any google search results on the given keyword. You only need to modify it to insert your google API key.
<?php
function check_result($keyword)
{
//your google API key
$key = "";
$url = "http://ajax.googleapis.com/ajax/services/search/".
"web?v=1.0&q=".$keyword.
...
Comments Read more
In PHP you can automatically get width and height of image file, so you don't have to write it manually. You can use this function to output your image in HTML code:
<?php
function print_image($imagepath)
{
$img_sizes = getimagesize($imagepath);
$width = $img_sizes[0];
$height = $img_sizes[1];
echo "<img...
Comments Read more
This function allows you to split strings with unicode characters into array with single letters as elements.
<?php
header('Content-Type:text/html; charset=UTF-8');
function uni_strsplit($string, $split_length=1)
{
preg_match_all('`.`u', $string, $arr);
$arr = array_chunk($arr[0], $split_length);
$arr =...
Comments Read more
The best way to embed flash object is using SWFObject javascript library. It automatically checks if visitor has flash player, what version, displays corresponding message, and you don't have to worry about those things.
To use SWFObject, you need to include javascript library in your <head> tags, then create div, which will...
Comments Read more
1 2 3 4 5 6 7 8 9 10