| 
					The Snippets Thread
				 | 
| 
					08-15-2011, 12:00 PM,  
(This post was last modified: 08-15-2011, 12:02 PM by MyDigitalpoint.)
				 | |||
| 
 | |||
| The Snippets Thread 
					Based on my own experience, snippets are a great way to learn PHP and sometimes a useful time-saver even if you know it because you can refer to these chunks of code for a quick integration into your coding. Let's post small snippets that can be useful to other members whether to learn or add extra functionality to a website or blog, in example, WordPress using the PHP executable plugin. The following snippet it's a directory listing so people can browse a directory on your site and even download files when you have setup a restriction via htaccess that does not allow directory listing: [/quote] Code: <?php
► MyDigitalpoint PRO Freelance Marketplace ◄
 | |||
| 
					10-02-2011, 11:35 PM,  
				 | |||
| 
 | |||
| RE: The Snippets Thread 
					This snippet is supposed to connect you to a mysql server and database using the basic mysql functions. PHP Code: <?php 
With love, HiddenKnowledge A.k.a. Yoruichi Shihouin If you have any questions, feel free to contact me trough email or pm. :) | |||
| 
					10-20-2011, 08:24 AM,  
				 | |||
| 
 | |||
| RE: The Snippets Thread 
					This snippet  generates random hexadecimal number to get HTML colors PHP Code: <?php This can be useful to randomize the background color of a website page or a section, such as the header or navigation bars this way: PHP Code: <div style="background:#<?php echo $color; ?>;">
► MyDigitalpoint PRO Freelance Marketplace ◄
 | |||
| 
					10-20-2011, 09:37 AM,  
				 | |||
| 
 | |||
| RE: The Snippets Thread 
					Here's one of the ones I find extremely useful when parsing user input. It's a regex function that takes all non-numeric characters out of a string. [source] PHP Code: preg_replace('/\D/', '', $string) Hi! I'm Zach, and I founded NiftyHost. If you need anything, just PM me! :) | |||
| 
					10-27-2011, 01:40 PM,  
(This post was last modified: 10-27-2011, 09:02 PM by Arthur.)
				 | |||
| 
 | |||
| RE: The Snippets Thread 
					When I saw this thread, I thought "Oh! I'll post my hex color code generator!", but obviously that would be pointless, as there already is one. So I'll post my snippet to delete all files in a directory (useful if you want to have a temp folder and it gets full of non-deleted useless files.) PHP Code: function empty_folder($folder){Function to highlight a string where $str is the string to be highlighted, $bg is whether it's the background or the text that's highlighted, and $color is what color to highlight it: PHP Code: function highlight($str, $bg=true, $color=false){ | |||
| 
					10-27-2011, 02:42 PM,  
				 | |||
| 
 | |||
| RE: The Snippets Thread 
					@Arthur: You might have some trouble with your first function. empty() is a pre-defined function in PHP.
				 Hi! I'm Zach, and I founded NiftyHost. If you need anything, just PM me! :) | |||
| 
					10-27-2011, 09:01 PM,  
				 | |||
| 
 | |||
| RE: The Snippets Thread 
					Oops. I posted a modified version of the function. The version I actually use is called delete_temp(). So I'll change the function name in my previous post. Thanks for noticing! | |||
| 
					01-18-2012, 02:33 AM,  
(This post was last modified: 01-18-2012, 02:33 AM by Serial Thrilla.)
				 | |||
| 
 | |||
| RE: The Snippets Thread 
					Some *nix / Linux batch script for HLDS Valve gaming servers. Half-Life Dedicated Server (HLDS): Code: #!/bin/bashReplace the "x" with your value and add other parameters if need. _______________________________________________________ Source Dedicated Server (SRCDS): Code: #!/bin/bashReplace the "x" with your value and add other parameters if need. _______________________________________________________ Create a empty file and paste this code, modify it, so it looks how you need it and save the file into the root folder of your server (where srcds_run or hlds_i686 is). Source: http://forum.singularity.us.to/thread-96.html (Yes, I'm the person called Technician) | |||
| 
					04-12-2012, 07:28 AM,  
(This post was last modified: 04-12-2012, 07:29 AM by Arthur.)
				 | |||
| 
 | |||
| RE: The Snippets Thread 
					PHP function to add a JavaScript alert ($id allows you to give it an identifier so you know which it is [perhaps a later version will allow auto-numbering]): PHP Code: function alert_flag($id=false){ | |||
| 
					« Next Oldest | Next Newest »
				 | 

 
 

 





![[Image: logo.jpg]](http://eorpg.com/templates/jade/logo.jpg)

![[Image: QnhsD.gif]](http://i.imgur.com/QnhsD.gif)