Articles tagged with: Code
Basic Class for creating a database connection Class MySQLConnection { // ———————– // variable initialisation // ———————– var $SERVER = “hostname”; // Server name var $USER = “dbusername”; // Database username var $PWD = “dbpassword”; // Database password var $DBNAME = “dbname”; // Database name var $DBCONN = “”; // ————————— // flag an error [read more...]
Using text fields on web based forms to obtain information from a website user can often lead to unexpected string inputs. A typical unexpected input might be a field that asks a user to submit a link and a description – spammers may use this description field to stuff with extra links. Fortunately, PHP has the command [read more...]
Session variables used to need registering however now they are more in line with _POST variables, so: On the page to activate Session Handling use session_start(); You can always check the Session is working by obtaining the Session ID using session_id(); Now variables can be registered and used using the form $_SESSION['variable'] = “value”; Removal [read more...]
Remembering the code or entity combinations for special characters when designing HTML pages can be a chore so I have been jotting them down as they crop up. Having a few moments spare I have put them together and uploaded v0.9 of a HTML Special Characters Poster in the downloads section.
Processing the Technorati API allows you to receive information about your blog and rankings logged with the Technorati service. An example of extracting various pieces of information is here $url = “www.yourchosendomain.com”; $apikey = “putyourapikeyhere”; $service = “http://api.technorati.com/bloginfo?key=” . $apikey . “&url=” .urlencode($url); // call the service and get results $xmlresult = file_get_contents($service); // results [read more...]
Obtaining information regarding elements in XML is relatively straight forward // xml input file $xmldoc = “sitemap.xml”; // test to open file if ( !$dom = domxml_open_file($xmldoc) ) { echo “The file cannot be loaded.”; } else { // show top level item $elem = $dom->document_element(); print_r( $elem ); } ?>
PHP Routine to highlight a keyword in any given phrase: function highlight( $phrase , $keyword) { $parts = explode( strtolower($needle), strtolower($phrase) ); $pos = 0; foreach( $parts as $key=>$part ) { $parts[ $key ] = substr($phrase, $pos, strlen($part)); $pos += strlen($part); $parts[ $key ] .= ”.substr($phrase, $pos, strlen($keyword)).”; $pos += strlen($keyword); } return( join( ”, [read more...]
It can be useful to set a placeholder in a web page, such as an image, and for this place holder to be set to be the latest file in a given folder; or to select a random image/file from a given folder and set it as the placeholder. For example in an image of [read more...]


