PHP


Update: ElStr.class.php goes to v1.2

php-iconThe PHP Class ElStr with usefull functions for modern greek unicode text manipulation, such as transcript greek to latin, or accent marks stripping is now updated to version 1.2

What’s new?

  • mixed case support for difthongs, etc:
    • μπ => mp or τζ => tz
    • Μπ => Mp or Τζ => Tz
    • μΠ => mP or τΖ => tZ
    • ΜΠ => MP or ΤΖ => TZ

  • Two new accent mark removal methods:
    • strtolower_no_accent($str) – that Convert unicode string to lower case, without accent marks for the greek letters
    • str_no_accent($str) – that Remove accent marks for the greek letters at passed unicode string (no any case convertion)

Examples

require('ElStr.class.php') ;
$txt = "Το μπαρμπουνάκι θέλει μπυρίτσα" ;
$elstrObj = new El_Str() ;

echo $elstrObj->to_latin($txt) ;
//echoes: To barmpounaki thelei byritsa

echo $elstrObj->strtoupper_no_accent($txt) ;
//echoes: ΤΟ ΜΠΑΡΜΠΟΥΝΑΚΙ ΘΕΛΕΙ ΜΠΥΡΙΤΣΑ

echo $elstrObj->strtolower_no_accent($txt) ;
//echoes: το μπαρμπουνακι θελει μπυριτσα

echo $elstrObj->str_no_accent($txt) ;
//echoes: Το μπαρμπουνακι θελει μπυριτσα

Downloads

Download v1.2      View Source


ElStr.class.php

php-iconA PHP Class with usefull functions for modern greek unicode text manipulation, such as transcript greek to latin, or upper case greek letters stripped from accent marks.

Functions
string to_latin($str)

  • Convert greek letters at the string to latins, as ISO:843 / ΕΛΟΤ:743 defines
  • $str string to convert
  • Returns converted string

string strtoupper_no_accent($str)

  • Convert unicode string to upper case, without accent marks for the greek letters
  • $str string to upper case convert
  • Returns converted string

bool is_upper($char, $notGreekException = false)

  • Check if $char is upper case
  • $char is the character for checking
  • If $notGreekException == true, throws exception when char is not greek
  • Returns true if $char is upper case, else false

bool is_lower($char, $notGreekException = false)

  • Check if $char is lower case
  • $char is the character for checking
  • If $notGreekException == true, throws exception when char is not greek
  • Returns true if $char is lower case, else false

Download      Frok it at Github

License
This project is free software, distributed under the terms & conditions of the FreeBSD License.


PHP random password generator

Here is a function for random password generation, could be useful in a lot of PHP projects.


/**
* @author Petros Kyladitis - 2012
* @license MIT License
*
* @description random password generator
* @param $min_length the minimum size of the password
* @param $length the maximum size of the password
* @param $chars a string contains all acceptable password characters
* @return a string with the generated password
*/

function rand_pass($min_length, $max_length=null, $chars="qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM"){
  //if $max_length param is not set, pass $length is the $min_length 
  //param, else a random number between min and max params.
  $length = !isset($max_length) ? $min_length : rand($min_length, $max_length) ;
  
  //the position of the last character of $chars variable
  $chars_end = strlen($chars) - 1;
  
  //variable for store password
  $pass ;
  
  //select a random char from the $chars & concatenate to the $pass
  for($i=0; $i<$length; $i++)
    $pass .= substr($chars, rand(0, $chars_end), 1) ;
  
  return $pass ;
}