Wappy's Php Snippets - I will place here usefull php snippets and functions that i learn/use

Pages: 1, 2
free web hosting

Read Latest Entries..: (Post #13) by iGuest on Jan 15 2008, 08:50 AM. (Line Breaks Removed)
WAP forum Wappy\'s Php Snippets H0w can I make my own wap forum on my wapsite using php/mySQL?Thank's... -=d(~_^)b=--question by Mark Anthony Gapoy
Read the FIRST post of this Topic. - Express your Opinion! Contribute Knowledge :-).

Open Discussion > CONTRIBUTE > Computers > Programming Languages > PHP Programming

Wappy's Php Snippets - I will place here usefull php snippets and functions that i learn/use

wappy
Here is a function you can use to generate a simple random password for whatever use ;-)

CODE
<?
function rand_pass($numchar){
$string = str_shuffle ("abcdefghijklmnopqrstuvwxyz1234567890");
$password = substr ($string, 1, $numchar);
return ($password);
}
//example
echo rand_pass('8'); // will return an 8 character long random password of numbers and letters like c8k4ss42
?>


Notice from serverph:
CODE tags added.


Here is an extremly usefull search function that will search a directory and its subdirectories for files including the given keyword and display a link to these files. I have made some great file search systems for wap sites using this ;-)

CODE
<?
function search($target, $directory){

   if(is_dir($directory)){
       $direc = opendir($directory);
       while(false !== ($file = readdir($direc))){

           if($file !="." && $file != ".."){

               if(is_file($directory."/".$file)){
                   if(preg_match("/$target/i", $file)){

$size = round(filesize($directory."/".$file)/1024,1);                                           echo "<a href=\"$directory/$file\">$file ($size KB)</a><br>";
                                       }
               }else if(is_dir($directory."/".$file)){
                   search($target,$directory."/".$file);

               }

           }
       }
       closedir($direc);
   }

   return;
}
?>


Notice from serverph:
CODE tags added.


If you use (or have ever stopped using mobiliichat due to the stupid clone bug...) READ THIS!

CODE
<?
//anti-CLONE v1.0 by wappy//
//this i mainly designed for the cloning problem thats bugged mobiliichat (a cool wap chat script i used as base code for my WAP CHAT) since its release. Hope you can make good use of it. I have lol!!!!//
//© wappyCULT 2006-2007//
//!!DO NOT REMOVE HEADER!!//
//if your using this on your site then sure remove this crap! But if you plan to give it out please keep the original contents intact!!!!!//

//!!PUT THE FUNCTION UP HIGH ON YOUR PAGE SO IT CAN BE USED ANYWHERE!!//

//build our function anti-CLONE!!!!! This is most of the important stuff out the way but we need to do a little more protection after he he he he he... Dumb clones..//
function anti_clone($string){
return ereg_replace ("[^[:space:]a-zA-Z0-9*_:-]", "", $string);
}

//ENTER THIS PART WHERE YOU NEED IT!//

//enter the value you want to protect from cloning, for mobilichat it is $nimi or you can see the general idea by now you can work it out and make your own layout... God im bored pmpl...//
$value_to_protect = YOUR_VALUE;

//use our anti-CLONE function!!!!!//
$value_to_protect = anti_clone($value_to_protect);

//add even more protection from enters an returns!!!!!//
$value_to_protect = ereg_replace("\n", "", $value_to_protect);
$value_to_protect = ereg_replace("\r", "", $value_to_protect);

//strip any unwanted tags//
$value_to_protect = striptags ($value_to_protect);

//make sure all letters are small!!!!!//
$value_to_protect = strtolower ($value_to_protect);

//enter your value again here... Last bit now pmpl//
YOUR_VALUE = $value_to_protect;

//THATS IT YOUR VALUE WILL NOW BE SAFE FROM spaces, symbols, funny A's, tags, enters, returns an all the other crap these idiots try ha... Im SURE ITS SAFE NOW! Someone should of done this along time ago!! If you find a gap mail me asap with details!!//

//if you try and claim you wrote this grrr at you, it because i spent hours on this cool mobiilichat BUG FIX!! lol!!!!//

//if you can't get this to work or need help etc... I couldn't give a ????... If however you wanna share/trade scripts etc mail me at wappyCULT@gmail.com//

//wappy from wappyCULT//
?>


Notice from serverph:
CODE tags added.


This is a good example of the strrev() command////

I used this simple function to determine the file extension of files on my site so i can put a unique icon next to each file thats listed. If you would like the icons (they are very small as designed for mobile/wap sites) you can get them at my wap site http://cul.t34.biz (please ignore the rude message at top its a test site i use for stuff ok)

CODE
<?
//icon code
$icon = "unknown.gif";
$rev = strrev ($file_name);
$exp = explode (".", $rev);
$true = strrev ($exp[0]);
$trueext = strtolower ($true);
if ($trueext=="zip" OR $trueext=="rar" OR $trueext=="gz"){$icon = "zip.gif";}
if ($trueext=="amr"){$icon = "amr.gif";}
if ($trueext=="midi"){$icon = "midi.gif";}
if ($trueext=="mid"){$icon = "mid.gif";}
if ($trueext=="gif"){$icon = "gif.gif";}
if ($trueext=="jpeg"){$icon = "jpeg.gif";}
if ($trueext=="jpg"){$icon = "jpg.gif";}
if ($trueext=="jad"){$icon = "jad.gif";}
if ($trueext=="jar"){$icon = "jar.gif";}
if ($trueext=="sis"){$icon = "sis.gif";}
if ($trueext=="bmp"){$icon = "bmp.gif";}
if ($trueext=="wbmp"){$icon = "wbmp.gif";}
if ($trueext=="txt"){$icon = "txt.gif";}
if ($trueext=="avi"){$icon = "avi.gif";}
if ($trueext=="thm"){$icon = "thm.gif";}
if ($trueext=="nth"){$icon = "nth.gif";}
if ($trueext=="png"){$icon = "png.gif";}
if ($trueext=="mmf"){$icon = "mp4.gif";}
if ($trueext=="wav"){$icon = "wav.gif";}
?>


Notice from serverph:
CODE tags added.


Here are a few snippets i was given by PhoenixBytes ;-)

CODE

/////////////////////////////////////////////////////////////////////////////////////
//
// this is the code i use for my search engine,
// the first if statement checks to see if this process has been done before or not,
// $stringy is only passed from the previous page with the cearch box on it, not from any 'back' or next links.
// the back and next links pass the $trimm variable
//
// so, if $trimm is empty, we must run $stringy through this code.
// if trim is NOT empty, we put $trimm through instead
//
// both variables are imported with the $malteasers variable
//
/////////////////////////////////////////////////////////////////////////////////////


if ($stringy == "") $malteasers = "$trimm";
else $malteasers = "$stringy";

$trimmed = trim($malteasers);


// this determines what characters can be used as a splitter, i.e 'space (%20)'
// this is so you can search for "chicken soup", "chicken" and "soup" all in one single query!
$trimmed_array = explode(" .%20.%2C.%26.%3F.%40",$trimmed);



// this foreach call was cut from my code (my code is on a loop)
// so this may work straight away or may need some editing,
foreach ($trimmed_array as $trimm);



// look for a slash
if (preg_match ("/\"/i", "$trimm"))
{

// do something with a function i'm sure is wrong, i may have taken a long way round when i was less experienced.
// $trimm = eregi_replace("/\"","",$trimm); might have worked instead of all the minusers and nudgers being needed!

$minuser = "2";

$trimm = eregi_replace("\"","",$trimm);

$preparetoslice = strlen("$trimm");

$sliceoffset = ($preparetoslice - $minuser);

$nudger = "1";

$trimm = substr($trimm,$nudger,$sliceoffset);
}



$query = "select count(*) from my_links where keywords LIKE '%$trimm%' AND valid='yes'";
$result = mysql_query($query);
$count = number_format(mysql_result($result,0,"count(*)"));


//
// if you wan't an ACCURATE search, let your text box pass a variable
// called $stringy
//
// then replace the database code with your own, but, keep the  "where keywords LIKE '%$trimm%'" part!
//
// and that should be it, good luck with search!
//
/////////////////////////////////////////////////////////////////////////////////////////////////
//
//
// Random link generation:
//

$query = "SELECT * from randylinks ORDER BY RAND(" . time() . " * " . time() . ") LIMIT 1";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
$rowrandy = mysql_fetch_array($result);


$linkname = $rowrandy["linkname"];
$linkurl = $rowrandy["linkurl"];
$randylink = "<a href=\"$linkurl\">$linkname</a>";

//
//
// just alter your database details to get this one working
// you need a db table that supplies a linkurl and a linktext
//
// optionally you can easilly add an image into it to create an image link
//
//////////////////////////////////////////////////////////////////////////////////////////////////
//
// MAKE WML COMPAT
//
// this is my make_wml_compat function, it should work though i have had issues with the carriage returns!
//


function make_wml_compat($string)
    {
    $string = ltrim($string);
    $string = ereg_replace(chr(13),"<br/>",$string);
    $string = ereg_replace(chr(10),"<br/>",$string);
    $string = ereg_replace("¶","<br/>",$string);
    $string = ereg_replace("µ","&nbsp;",$string);
    $string = ereg_replace("===","<br/>",$string);
    $string = ereg_replace("\n","<br/>",$string);
    $string = ereg_replace("\r","<br/>",$string);
    $string = ereg_replace("&","&amp;",$string);
    $string = ereg_replace("\\$","$",$string);
    $string = ereg_replace("\","£",$string);
    $string = ereg_replace("<","&lt;",$string);
    $string = ereg_replace(">","&gt;",$string);
    $string = ereg_replace("","-1",$string);
    $string = ereg_replace("","-2",$string);
    $string = ereg_replace("","-3",$string);
    $string = ereg_replace("","-euro",$string);
    $string = ereg_replace("","©",$string);
    $string = ereg_replace("","®",$string);
    $string = ereg_replace("~club","♣",$string);
    $string = ereg_replace("~spade","♠",$string);
    $string = ereg_replace("~heart","♥",$string);
    $string = ereg_replace("~diamond","♦",$string);
    $string = ereg_replace("~1","¹",$string);
    $string = ereg_replace("~2","²",$string);
    $string = ereg_replace("~3","³",$string);
    $string = ereg_replace("~half","½",$string);
    $string = ereg_replace("~quart","¼",$string);
    $string = ereg_replace("~euro","€",$string);
    $string = ereg_replace("~dot","•",$string);
    return $string;
    }
//
//
// this SHOULD work, however, different servers run different versions of php etc, so if you get an error on
// say, line 3452345, then find the symbol on that line and google php escape %symbol%
// an escape is to stop php parsing it, look at the dollar sign up there,
// it's escaped with two back slashes.
//
// you can use the above function like this: make_wml_compat("$text");
// it will do nothing if you don't call it.
//
// enjoy!
///////////////////////////////////////////////////////////////////////////////////////////////////
©PhoenixBytes



Notice from serverph:
CODE tags added. and finally merged FIVE successive posts in same thread. warning served as well. please review trap17 forum rules & TOS here.

 

 

 


Reply

biscuitrat
Oooh, nifty cool. Reminds me of a Firefox plugin for encrypting passwords. Very nice smile.gif

Reply

wappy
Yeah the random password thing can come in handy for email registration etc.

Reply

juice
But rememeber, even fixing the scripts wont help sometimes because you have just released your wappy_anti_clone and now hackers and other misfits can maybe get around it. Thats normally what happens - bugs are fixed just to have more bugs formed ph34r.gif

Reply

wappy
sigh.. maybe i should stop releasing stuff then juice? Eh look dude there are NOT many people like dj.dance who will stalk and try to ruin everything i do, there is something wrong with people like that. If you install that it WILL MAKE IT HARDER BY FAR TO DO IT. have you seen me get cloned yet? nO. I don't know why i bother sometimes. When your on top jealous spoilt brats just try to bring you down. To be honest i thought about banning both the popular sa networks from my site all together as all the trouble comes from this country. Well at least 90percent of it does anyway. It drives me CRAZY and here is my escape, i really don't want to talk about the dark side of wap here ok.

Reply

Tetraca
D you mind if I put this stuff in my source code wiki? I will give you credit if you do allow me to.

Reply

wappy
yes by all means :-) you can use it :-)
what do you mean by credit like a link? If yes my wap site is http://cult.trap17.com or my web site is http://cult.trap17.com/forum :-) im wappy from © wappyCULT
I hope you can make good use of these snippets :-)

Reply

Tetraca
I meant linking to this topic from the wiki page, but I can link to your site if you wish. Thanks!

Reply

wappy
yes thanks i would rather you link to my site if possible. Wap or web i don't mind.
Enjoy :-)

Reply

Chatz
Come on wappy I'm from sa and all I do is defend you aganst dj and his little kid followers.The only thing is that sa's got some of the best hackers in the world.

Reply

Latest Entries

iGuest
WAP forum
Wappy\'s Php Snippets

H0w can I make my own wap forum on my wapsite using php/mySQL?
Thank's... -=d(~_^)b=-

-question by Mark Anthony Gapoy

Reply

wappy
i already said i won't ban the networks but as i said had been very tempted in the past. And yes there is alot of za people on wap bro.

Reply

juice
Yes wappy but banning the SA networks will just make things worse, I'm in SA so please don't ban the SA networks sad.gif FACT: The people from SA are some of the most addicted wappers around! laugh.gif

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Pages: 1, 2
Recent Queries:-
  1. free mobilichat script - 51.12 hr back. (1)
  2. php snippet info about browser - 64.15 hr back. (1)
  3. mobiilichat - 99.04 hr back. (1)
  4. snippets phoenixbytes - 186.96 hr back. (1)
  5. php text cut snippet - 263.56 hr back. (1)
  6. php mobile sites snippets - 287.32 hr back. (1)
  7. search engine php snippet - 311.95 hr back. (1)
  8. wappycult: wap community script - 348.43 hr back. (1)
  9. your own wap site wappy - 490.06 hr back. (1)
  10. >> enter your keyword(s) or an link-url here << - 6.42 hr back. (69)
  11. php snippet link spider - 501.17 hr back. (1)
  12. php ereg_replace euro - 517.94 hr back. (1)
  13. snippets functiopns php - 519.79 hr back. (1)
  14. wappycult how to install - 521.19 hr back. (1)
Similar Topics

Keywords : wappys, php, snippets, place, usefull, php, snippets, functions, learn

  1. Functions
    ??? (9)
  2. Php Email Validation
    A PHP data validation class with many functions (1)
    I've been reading through my old php book (PHP 4.1) and came across this data validation class.
    It can check a number of things ranging from telephone numbers , credit card number formats, email
    address and some others. I checked out some of the methods although I didnt expect it to work 100%
    because I've found source code errors thoughout the book and CD. I tested out a few of the
    methods to check and some of them did return expected results but some didnt either so the data
    validation class was not perfect and it didnt really bother me. The cool thing I found....
  3. Php Functions To Send Mail
    (9)
    Which other methods to send mail from a form? I just know mail function, like: mail(string to,
    string subject, string message) Has anyother?....
  4. Arrays Outside A Function
    Need to have arrays available to all functions. (3)
    I've got a bunch of arrays that i want to use for more then 1 function. when i declear the
    arrays outside a function i cant use it in a function. This code was originally written in
    javascript by another person but since I plan to use it and extend it with php I had to change it
    from javascript to php code. In the javascript code the arrays were decleared outside the functions
    with 'var arrayname' I read somewhere that declearing javascript variables with
    'var' gives it global access. Any ideas on how I can go about declearing 1 set of these
    arrays t....
  5. Encrypt Functions
    (0)
    Here is my 3rd Code: By this code you can encrypt your text: CODE <?php $a =
    md5("hello"); $b = base64_encode("hello"); $c =
    base64_decode("hello"); print "md5 = ".$a." base64_encode =
    ".$b." base64_decode = ".$c; ?> EASY!....
  6. Some Basic Php Code Snippets For All Levels Of Experience
    (3)
    Most of the code snippets are usually used for community driven sites but they do give some general
    idea on how php works. Don't forget if your starting out php for the first time that when
    saving php files that you need to have the .php extension on your files or they will not work.
    Display Browser info This piece of code displays a user's browser info on how they are seeing
    the website CODE <?php echo $_SERVER["HTTP_USER_AGENT"]; ?>
    Actual Display- QUOTE Firefox - Mozilla/5.0 (Windows; U; Windows NT 5.1; ....
  7. [php](simple) Using Functions To Combine Values In A Form
    Really simple example on how to combine values with function (2)
    I just learned this simple method on how to use functions to combine two values from a form. First
    we create ourselves a simple POST form CODE <form method="POST"> Name:
    <input type="text" name="nickname"> Location: <input
    type="text" name="location"> <input type="submit"
    value="Input"> </form> Now we add this php to that same file CODE
    <?php $nick = $_POST['nickname']; $location =
    $_POST['location' ....
  8. Gd Functions
    Questions (2)
    Hi all I want begin a new project , my new project is Photo blog ( weblog and image album ) in one
    script for example you can post many image in one post at once case . so its very good and very easy
    but we have some problems . if you can plz help me to fix this problems for example : we need
    change image size for page speed ( we dont want show 16 image in one page ) * we need GD functions
    to change image size to smaller and then show smaller image at page if you know source or tutorial
    about change image size plz post here . thankx we know we can change image size (w....
  9. Wap Redirection
    Usefull code that all wap site owners should use! (12)
    Use this code to redirect pc users from your wap site to web site: include above page header this
    code: CODE <?php $mywebsite = "forum/index.php"; $browser = explode
    ('/', $HTTP_USER_AGENT); if($browser[0]=="IE"){
    header ('Location: $mywebsite');} ?> ....
  10. Some Php Functions Explaination Required
    (2)
    Can some one please tell me what is the purpose of the following functions , although there's a
    little explaination with everyline but i cant understand, can some one exaplin it bit clearly and
    tell me that why it is needed in config.inc.php.. what is its purpose and will it work if i dont
    include these files in config.inc.php thanks QUOTE ### Url were Website has been installed, not
    '/' in end! define('C_URL','http://www.test.com/Website'); ### Internal
    path to Website directory define('C_PATH','Z:/home/www.test.com/www/....
  11. Globals Inside Functions
    (4)
    I've got the following function, that has a function inside of it, when I run it I get the
    followin error: PHP Code: CODE Fatal error: Call to a member function on a non-object in
    See the code below where I get the error message. I'm guessing the scope of my varaibles is
    messed up, but I'm not sure how to fix it. I've abbreviated the code so as to make it easier
    to read. PHP Code: CODE function getMemberRegistrationForm( &$tpl, &$db ) {
       function displayRegistrationForm( $action, &$db, $defaults =....
  12. Using The Image Editing Functions Of Php
    Specifically, lines or regular polygons. (4)
    I've been experimenting a little with PHP's image functions and I was trying to see if I
    could make something that looked 3D, so I started with a cube because it's simple. To make an
    isometric picture of a cube, you need to start with a regular hexagon. However, making a regular
    hexagon isn't the easiest thing. Is there a function to create a regular polygon, or specify an
    angle and magnitude for a vector?....
  13. Writing Your Own Functions In Php
    how do i write php functions that takes arguments in php? (2)
    I'll set up the background for the question: I have a separate file that I include on all the
    webpages on my site which I call with PHP using the include() function, so everything will be much
    easier to maintain and update. Well, I have three include files for each page: header.php (includes
    stuff like meta tags, googlebot/spider info), footer.php (the footer/copyright thing), leftnav.php
    (includes the navigation bar). I also like the titles of my pages to be as descriptive as possible
    so I try to include the path of a page (how the user got to that page: "Excite Y....
  14. Confused...
    some php functions that i am confused (5)
    First of all, if you have answers to the following QUOTE
    http://www.trap17.com/forums/A-Lot-Of-Php-...ions-t7653.html
    http://www.trap17.com/forums/A-Lot-Of-Html...ions-t7651.html Feel free to answer them all. Now,
    in PHP i know there's microtime, srand, float, array_rand, arrays, foreach, or any other loop
    functions. i'm really confused . Please help me!....
  15. Links To Lots Of Usefull Website
    I AM NOT SPAMING THIS TOOK ME 15 MINUTES (1)
    HELLO HERES A LIST OF LOTS OF USEFULL SITES I FOUND: || Codecs || http://www.free-codecs.com
    http://www.codecsdownload.com http://www.freecodecs.net http://www.click-now.net
    http://www.click-now.org || Search Engines || www.google.com www.search.com www.altalavista.com
    www.AllSearchEngines.com www.mamma.com || Programming Help Sites || www.patorjk.com
    www.planet-source-code.com www.freevbcode.com www.codearchive.com www.vbaccelerator.com
    www.vbcode.com www.abstractvb.com www.developerfusion.com www.codeproject.com www.extreme-vb.net ||
    Free Online Game Play || ....

    1. Looking for wappys, php, snippets, place, usefull, php, snippets, functions, learn

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for wappys, php, snippets, place, usefull, php, snippets, functions, learn

*MORE FROM TRAP17.COM*
advertisement



Wappy's Php Snippets - I will place here usefull php snippets and functions that i learn/use



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE