php codes

Discussion in 'PHP' started by darky00001, Jun 12, 2008.

  1. #1
    Use the current filename as the HTML body id
    // Makes the body id = the current filename - extension
    // Useful while working on static markup that relies on styles/scripts targeting the current page

    <?php
    $page = $_SERVER['PHP_SELF'];
    $page = str_replace("/","",$page);
    $page = str_replace(".php","",$page);
    ?>

    <body id="<?php echo $page ?>">




    Random password generator in php
    A little function which generates random password of a certain length it uses all letters both lowercase and uppercase and all number

    //generates a random password which contains all letters (both uppercase and lowercase) and all numbers
    function generatePassword($length) {
    $password='';
    for ($i=0;$i<=$length;$i++) {
    $chr='';
    switch (mt_rand(1,3)) {
    case 1:
    $chr=chr(mt_rand(48,57));
    break;
    case 2:
    $chr=chr(mt_rand(65,90));
    break;
    case 3:
    $chr=chr(mt_rand(97,122));

    }
    $password.=$chr;
    }
    return $password;
    }




    Convert from tis to utf

    <?php
    $content = @file_get_contents("http://www.manager.co.th/RSS/Sport/Sport.xml");
    header("Content-Type: text/xml; charset=utf-8");
    echo iconv('windows-874', 'utf-8', $content);
    ?>
     
    darky00001, Jun 12, 2008 IP
  2. itcn

    itcn Well-Known Member

    Messages:
    795
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    118
    #2
    heh, useful functions
     
    itcn, Jun 12, 2008 IP
  3. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #3
    EricBruggema, Jun 12, 2008 IP