332 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
Member Avatar for diafol

# As of 4/4/2013 # This class has now been updated and posted here: http://www.daniweb.com/web-development/php/code/451674/all-in-one-daniweb-api-class# # ORIGINAL POST # This code can be used to retrieve a forum list with various options with regard to display. This class could be extended for articles, posts, etc etc. The retrieval methods include …

Web Development api daniweb-api json php
Member Avatar for diafol
3
455
Member Avatar for pritaeas

## RSS Class ## The code snippet is a PHP class for retrieving RSS feeds from the DaniWeb website. There are two exposed methods, one for retrieving the list of predefined article types, and another to get a specific RSS feed. If you pass parameters to this method, there is …

Web Development daniweb-api php xml
Member Avatar for pritaeas
1
568
Member Avatar for pritaeas

## API Mashup ## This example is a mashup of [diafol's class](http://www.daniweb.com/web-development/php/code/451428/daniweb-api-class-for-getting-forums), [Dani's parsing code](http://www.daniweb.com/api/documentation) and [my class](http://www.daniweb.com/web-development/php/code/451390/daniweb-api-rss-class). It uses diafol's dwAPI class to retrieve a list of all forums, loops through them, and uses my Rss class to get the respective RSS feeds. It will show each forum in …

Web Development api daniweb-api php
Member Avatar for diafol
0
552
Member Avatar for joshl_1995

Hello Community, I have been looking for a facebook news feed api, i couldn't find one. All i could find is bits of script for construct my own news feed api. So thats what i did and i thought i might share the script with you it's a bit messy …

Web Development api display php social-media
1
575
Member Avatar for Scribbller

Format a local time/date according to locale settings

Web Development php
Member Avatar for LastMitch
1
218
Member Avatar for JorgeM

Here is my first attempt at creating a simple slideshow. Contributions to making this more efficient are welcomed! #jsFiddle --> [Demo](http://jsfiddle.net/wGnEm/1/)

Web Development javascript
Member Avatar for JorgeM
5
264
Member Avatar for ipster

#Web app state management# The current state of the user interface determines which application actions are enabled and thus which html elements are enabled for the user to invoke them. Classes are used in the html to indicate elements that need to be managed. Then jQuery is used to configure …

Member Avatar for LastMitch
2
359
Member Avatar for nakor77

This snippet will allow you to easily work with session variables in your applications. This example is using a string type but it works the same for any data type, you would just need to change the default return value from string.Empty to something more appropriate.

Web Development asp.net session
Member Avatar for LastMitch
0
218
Member Avatar for pritaeas

The following snippet will show, how you can pass a data array to a function, and generate a table with N columns. `$data` contains some dummy data, which can come from any data source. Then you call `createHtmlTable` passing the data, the number of columns you want, and a function, …

Web Development php
Member Avatar for LastMitch
3
532
Member Avatar for veedeoo

Hello Everyone, Please accept my simple and humble contribution. This script will validate if the user or visitor is a suspected spammer, by utilizing the stopforumspam API. Example implementation ## example usage. These items can be from database or from form input. The choice of implementation is all up to …

Web Development abuse api php
Member Avatar for LastMitch
5
241
Member Avatar for Echo89

Here is a fully working PHP page viewer, set the variables $pages[] = "ANY URL HERE"; to suit your needs, and change the variable $max = 10; to however many views you want for each $page. -Echo

Web Development php
Member Avatar for Echo89
1
454
Member Avatar for RamiroS

This is one of the fastest ways to get data submitted by a HTML form, make it readable and send it by e-mail. Fast and easy. From the raw example to some basic functionality.

Web Development php
Member Avatar for mlesniak
0
256
Member Avatar for vibhaJ

I was struggling long for proper image resize function for maintaining image ratio. Finally i end end up with merging and changing all codes and it works ! function resizeImage($sourceFile,$destFile,$width,$height) sourceFile => Full path along with filename destinationFile => Full path along with filename I hope this will help coders..

Web Development image php
Member Avatar for diafol
1
338
Member Avatar for Killer_Typo

I got bored and started some scripting the other day in PHP, this is just a sample that i wrote, just uncomment the part of script that you would like to see. IE remove the /* and */ around a certain area. i know its not great, but some beginners …

Web Development php
Member Avatar for LastMitch
0
149
Member Avatar for pritaeas

Below is a documented code example showing how to use the SQLite3 class to connect and query your database (and check for errors). IMHO using PDO is a better alternative, as this extension uses mixed technology in a non-standard way (objects, arrays and exceptions). If there are any questions let …

Web Development php sqlite
2
4K
Member Avatar for pritaeas

Below is a documented code example showing how to use the SQLite functions to connect and query your database (and check for errors). Please note that using the SQLite extension is NOT RECOMMENDED. This extension is no longer available in PHP 5.4.0. If you want your scripts to be future …

Web Development php sqlite
2
589
Member Avatar for pritaeas

This demo will show a PHP script using a Smarty template. It assumes basic installation. In the folder where you copy the script, there should be a smarty folder containing the Smarty files. You should create a writable `cache` and `templates_c` folder, and a folder called `templates` where the `.tpl` …

Web Development php ui-ux
Member Avatar for pritaeas
2
532
Member Avatar for jstfsklh211

A simple way for using templates in php new pages can run server side code or pretty much do anything you would normally want to do on a web page First create your template. cleary there is way more that can be done with this, I've kept it simple for …

Web Development php
Member Avatar for jstfsklh211
0
433
Member Avatar for jstfsklh211

to create a new comboBox when you post your form checkbox_name will contain the selected value $(document).ready(function() { var cb = "checkbox_name"; comboBox(document.getElementById(cb+"CB"), cb); var sel = myForm.elements[cb+"_hold"]; sel.length = 0; //add options sel.options[sel.options.length] = new Option("text", "value"); }); <div id="checkbox_name"></div>

Web Development javascript
0
369
Member Avatar for Echo89
Member Avatar for Airshow

Tablesorter (currently v2.0.5) includes an "update" method. This method keeps a Tablesorter object up to date with dynamic changes made to its table(s). Like other Tablesorter methods "update" is implemented in the form of a custom event. A typical method call would be $table.trigger("update"); , where $table is a jQuery …

Web Development javascript javascript-jquery
Member Avatar for punknroll
0
822
Member Avatar for pritaeas

Below is a documented code example showing how to use the [PDO](http://php.net/pdo) classes/objects to connect and query your database (and check for errors). If there are any questions, or you want to see different features, let me know. UPDATE: I've encountered a problem with PDO and bit fields (MySQL). If …

Web Development php
Member Avatar for sammry
2
3K
Member Avatar for pritaeas

Below is a documented code example showing how to use the [MySQLi](http://php.net/manual/en/book.mysqli.php) (MySQL improved) classes/objects to connect and query your database (and check for errors). If there are any questions, or you want to see different features, let me know.

Web Development mysql php
5
4K
Member Avatar for pritaeas

Below is a documented code example showing how to use the [MySQL functions](http://php.net/manual/en/book.mysql.php) to connect and query your database (and check for errors). Please note that using the MySQL extension is **NOT RECOMMENDED**. This extension is no longer maintained and will be deprecated soon. If you want your scripts to …

Web Development mysql php
3
865
Member Avatar for Troy III

# This is a simple HTML String Sanitizing tool. # ## It allows a highly rich,- but safe - html content input to be published on your pages. ## **The script code is very light and to some degree customizable.** * This function takes care of blacklisted tags, which are …

Web Development html-css javascript
Member Avatar for Troy III
2
274
Member Avatar for felgall

JavaScript doesn't actually have a sleep() function corresponding to what is available in other languages. We can easily implement one though. The following code uses afunc as an example function where we want to be able to have the code sleep for a number of milliseconds between sections of code. …

Web Development javascript
Member Avatar for Troy III
0
367
Member Avatar for Troy III
Member Avatar for Troy III
0
362
Member Avatar for Troy III

With this *Spartan*, we can destructively disable all the links on the page. (Or whatever link collection we feed the Fn.arg.)

Web Development javascript seo
Member Avatar for Troy3
0
185
Member Avatar for pritaeas

In addition to [my post in this thread](http://www.daniweb.com/web-development/php/threads/429740/php-best-practice#post1841569) I've decided to post an extended example, which also implements functions for inserts and updates. I hope the code is straightforward enough. If not, reply and let me know. The table structure I've used for my test is the following: CREATE TABLE …

Web Development data-structure php
Member Avatar for extjac
4
453
Member Avatar for Graphix

Hey everybody, Lately I have written the game Hangman in many different languages (C, JavaScript, Java and PHP so far). Here is the code snippet for JavaScript! It uses a words file, on the bottom of this post you will see a small example of a few words. The source …

Web Development javascript politics puzzle
Member Avatar for rotten69
-1
2K
Member Avatar for ReDuX

This is a very simple statistics script that provides for services on/offline, memory info, server load averages and uptime and lastly drive info. Its easily customised and i have usef <font> alot where you could have set come css and have it all done easily and look a bit more …

Web Development php
Member Avatar for ReDuX
0
172
Member Avatar for tyson567

//$time in the second php code hold the time stored in the database in the same format as above(ie TIMESTAMP Format) //Save the first php code as timeago.php //include first php code u saved in the second php code as i have done.. //Use the Second Php code Wherever You …

Web Development php
Member Avatar for tyson567
0
1K
Member Avatar for Wraithmanilian

If you ever go to [URL="http://www.hostip.info/"]http://www.hostip.info/[/URL], you will find a Community Geotarget IP Project. The great thing about it is that it is free to use. :) Now, this is just a snippet of code to begin working in the world of GeoIPs. There's a lot more info to be …

Web Development lan-wan php
Member Avatar for sammry
0
443
Member Avatar for cereal

Hi! *Minimize HTTP requests*. One of the suggestion I always read is to combine files, so I made a little Class that merges files on the fly, the supported formats are CSS and Javascript. With little efforts, I think, it can work fine also with JSON and CSV. Usage is …

Member Avatar for cereal
1
335
Member Avatar for cwarn23

In these three functions, you can filter to a url to just the domain name. There are three main methods of doing so which are all shown in the example and the usage of each function is shown in the example.

Web Development php
Member Avatar for diafol
0
745
Member Avatar for kaleem_ullah

I have developed a contact us page and also PHP code that works perfect. Know the only problem is that after submitting the form it shows only "Message sent" on a new page. I want that after submitting the form page will redirect back to home page. It is only …

Web Development gui php
Member Avatar for cjohnweb
0
3K
Member Avatar for vindom

Hi! Im a noob to PHP but had to use it instead of ASP because I couldn't retrieve images from database using ASP + MS Access... Anyways.. I have couple questions: Number 1: How to retrieve and displaymultiple(!) images(jpg) from mysql DB? NUmber 2: I have a main page that …

Web Development http-protocol php seo web-browser
Member Avatar for grant.baker
0
296
Member Avatar for jhbalaji

Hello, Many guys have been asking for this sort of sms scripts! Any way i have created one for personal use but i am sharing here :) Things you need [LIST] [*]An Account in tm4b.com and PHP 5. [*]cURL or allow_url_fopen enabled in php.ini [/LIST] - [URL="http://jhbalaji.com"]Balaji J H[/URL]

Web Development php
Member Avatar for abhishek123465q
1
1K
Member Avatar for Troy III

We know we already have built-in [I]Trim methods[/I], but trimming doesn't get rid of internal, (and unwanted) extra spaces. -So this is where Normalize method comes to play. It trims left, it trims right, but most importantly it also trims on the inside, one could say: "it trims inside-out". In …

Web Development algorithm javascript
Member Avatar for Troy III
0
325
Member Avatar for turt2live

Simply enough: Call the function, get the returned filename. Function Variables: $file : The input file (source/background) $destination : Where you want the new watermarked image to go $overlay : The overlay image (foreground), this is default set (if not passed in) to "images/watermark.png" $X : X-Position of overlay (default …

Web Development php
Member Avatar for webatz
1
525
Member Avatar for Troy III

[I][COLOR="Green"]!below is the code snippet [/COLOR][/I] This is a multi-use property toggler. In the given example we are toggling a sub property of an element. e -is the property owner to be targeted; p - is the property name to be set; v - is the property value; henceforward changing …

Web Development javascript
Member Avatar for Airshow
0
246
Member Avatar for vishalrane

All the webpage data will be converted into PDF file, You can also add details such as ur name etc by using Chunk chunk1 = new Chunk("By Vishal RAne, [email]vishalrane50@example.com[/email] \n",FontFactory.GetFont("Verdana", 8)); The pdf will be saved on desktop.... u can change location by using PdfWriter.GetInstance(Doc, new FileStream(Environment.GetFolderPath (Environment.SpecialFolder.Desktop)+ "\\VishalRane.pdf", …

Web Development asp.net pdf
Member Avatar for SummiRS
1
336
Member Avatar for gameon

here is my code i want update the two fields without refreshing whole page....

Web Development asp.net
0
126
Member Avatar for jstfsklh211

I hate websites that timeout and don't let you know about it this script pops up a message when you timeout and allows you to re-login in place

Web Development javascript
0
300
Member Avatar for pinkygirl
Member Avatar for partha.asp
0
364
Member Avatar for essential

It performs the toggle function to change the class of the paragraph tags and reverts back to the default class name when user rollout of it. You can embed the CSS style code inside the Head section of your page using HTML style tag. Code is as follows :

Web Development html-css javascript
Member Avatar for tekagami
0
255
Member Avatar for meabed

This is CURL Ready function , to use it just call do post if the page you are calling has post variables , or get if it has get variables :)

Web Development php
Member Avatar for cereal
0
418
Member Avatar for serkan sendur

To make some operations on XML elements you have to know their types. This snippet is about getting the types of these elements.

Web Development asp.net xml
Member Avatar for deepalijain
0
238
Member Avatar for turt2live

What this script does is take in an image and export a thumbnailed version. Function Arguments: $file : Desired image to create a thumbnail of $destination : End location for the thumbnail $zoom : Setting type, explained later (default: false) $t_width : Thumbnail width (default: 150) $t_height : Thumbnail height …

Web Development php
Member Avatar for turt2live
0
541
Member Avatar for mikeSQL

Create the HTML we will be using. I will show the whole code and then break it down so you can see what each thing does. Let's start. Create a new html file called [B]index.html[/B]. HTML Code: [COLOR=#000080]<html>[/COLOR] [COLOR=#000080]<head>[/COLOR] [COLOR=#000080]<title>[/COLOR]AJAX Demo[COLOR=#000080]</title>[/COLOR] [COLOR=#800000]<script src='getnv.js'>[/COLOR][COLOR=#800000]</script>[/COLOR] [COLOR=#000080]</head>[/COLOR] [COLOR=#000080]<body>[/COLOR] [COLOR=#000080]<div id='menu'>[/COLOR] [COLOR=#000080]<ul>[/COLOR] [COLOR=#000080]<li>[/COLOR][COLOR=#008000]<a onClick='check_content("page.php?id=index")'>[/COLOR]Home[COLOR=#008000]</a>[/COLOR][COLOR=#000080]</li>[/COLOR] …

Web Development php
Member Avatar for kosher_12
0
247

The End.