Daily Technology News, Tips, and Reviews | Subscribe to Jason Slater Technology BlogTechnology Feed | Join Jason Slater on TwitterTwitter | Thursday 2nd September 2010

Articles tagged with: Code

PHP: Establish Class for MySQL Connections
Tuesday, 18 November 2008
PHP: Establish Class for MySQL Connections

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...]

PHP: Removing HTML Tags from Strings
Tuesday, 28 October 2008
PHP: Removing HTML Tags from Strings

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...]

PHP: Session Variables
Wednesday, 22 October 2008
PHP: Session Variables

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...]

HTML Special Characters Poster
Friday, 3 October 2008
HTML Special Characters Poster

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.

PHP: Process Technorati API
Friday, 3 October 2008
PHP: Process Technorati API

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...]

PHP: XML element information
Friday, 3 October 2008
PHP: XML element information

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: Highlight a keyword in a phrase
Thursday, 14 August 2008
PHP: Highlight a keyword in a phrase

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...]

PHP: Select the latest image or file in a folder
Wednesday, 23 July 2008
PHP: Select the latest image or file in a folder

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...]