add

Friday, May 17, 2013

Regex in PHP

1. 1 Character 1 number and string length
^\S*(?=\S{8,})(?=\S*[a-z])(?=\S*[A-Z])(?=\S*[\d])\S*$

  • ^: anchored to beginning of string
  • \S*: any set of characters
  • (?=\S{8,}): of at least length 8
  • (?=\S*[a-z]): containing at least one lowercase letter
  • (?=\S*[A-Z]): and at least one uppercase letter
  • (?=\S*[\d]): and at least one number
  • $: anchored to the end of the string
To include special characters, just add (?=\S*[\W]), which is non-word characters

OR

(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$
   * contain at least (1) upper case letter
   * contain at least (1) lower case letter
   * contain at least (1) number or special character
   * contain at least (8) characters in length



References
1. http://www.autohotkey.com/docs/misc/RegEx-QuickRef.htm
2. http://www.regular-expressions.info/index.html

Zend perks

Zend perks

1. StringLength Validator in Form
$this->addElement('text', 'password', array(
    'label' => 'Password:',
    'required' => true,
    'filters' => array('StringTrim'),
    'validators' => array(
        array('StringLength', false, array(8,20))
    )
));
Another way doing the same thing
$this->addElement('textarea', 'comment', array(  
    'label' => 'Please Comment:',  
    'required' => true,  
    'validators' => array(  
        array('validator' => 'StringLength', 'options' => array(0, 20))  
    )  
)); 

2. Regular expression

To use a regular expression in zend you regex mus b enclosed in (/) like /regex/
$this->addElement('text', 'password', array(
    'label' => 'Password:',
    'required' => true,
    //'filters' => array('StringTrim'),
    'validators' => array(
        array('StringLength', false, array(8,20)),
        array('regex', false, array('pattern' => '/^\S*(?=\S{8,})(?=\S*[a-z])(?=\S*[A-Z])(?=\S*[\d])\S*$/'))
    )
));


Thursday, May 16, 2013

little things BIG time saving (Some important php Functions)



1. array_filter()
simply remove null/empty values froma an array.
$entry = array(
             0 => 'foo',
             1 => false,
             2 => -1,
             3 => null,
             4 => ''
          );
print_r(array_filter($entry));
OutPUT
Array
(
    [0] => foo
    [2] => -1
)

2. readCSV
this function simply takes csv filename(with path) and return an array
function readCSV($csvFile) {
    $file_handle = fopen($csvFile, 'r');
    while (!feof($file_handle)) {
        $line_of_text[] = fgetcsv($file_handle, 1024);
    }
    fclose($file_handle);
    return array_filter($line_of_text);        
}
            

Tuesday, May 7, 2013

Zend Resources


  • Zend Ajax
    • http://blog.jtclark.ca/2010/03/zend-framework-and-ajax/
  • Chained dropdowns 
    • http://www.codeassembly.com/Simple-chained-combobox-plugin-for-jQuery/

Sunday, May 5, 2013

On Sunday 5-5-2013=>
1.Add the form to the page index.php,
  • i have done this by drag and drop form into body of index.php
  • then drag and drop button from html component.
2.Transfer the data to the next php file and named it wishlist.php.

  • use $_GET method for transfering of data from one form to other
3.Create a web page wishlist.php

4.Establish the connection,

Saturday, May 4, 2013

2013 may 05 : starting to learn php

8:00 PM => I started learning php from a tutorial of netbeans.link of the tutorial is https://netbeans.org/kb/docs/php/wish-list-lesson2.html.
here i learnt the following
  1. downloaded netbean
  2. downloaded jdk and installed
  3. downloaded wamp and installed
 9:00 PM => started database connectivity through mysql jdbc in netbeans .
  1. created table of wishers
  2. created table of wishes
  3. inserted data in tables
  4. created simple form and posted its value on next page
 ERROR : I had the following errors

CREATE TABLE wishes2(
 id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
 wisher_id INT NOT NULL,
 description CHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
 due_date DATE,
 FOREIGN KEY (wisher_id) REFERENCES wishers2(id)
)
  1. Error code 1005, SQL state HY000: Can't create table 'saqi.wishes2' (errno: 150)
    Line 1, column 1
  • Solution : error was becuase i did not create the parent table for which i was creating a foreign  key and wishers2 table
10:00 PM

Tuesday, March 26, 2013

cell padding and cell spacing in HTML

We can beutify our page by simple cellspacing and cell padding.
just have a look at code and output at the bottom.
<html>
<head>
<title>cell Padding</title>
<style>
div.pageoverflow {
clear: left;
padding-top: 1px;
width: 350px;
overflow: hidden;

}

div.pagecontainer {
background-color: #ececec;
margin: 10px;
padding: 5px;
border: solid 1px #666;
}
p.pagetext {
color: #384654;
float: left;
padding-top: 5px;
padding-right: 5px;
width: 30em;
margin-bottom: 0.5em;
font:Arial, Helvetica, sans-serif;
font-size:12px;
}

</style>
</head>
<body>
<table width="100%" style="background-color: #FFFFFF;">
<tbody><tr>
<td>
<table width="100%" cellspacing="2" cellpadding="7">
<tbody><tr style="background-color:#ECECEC"><td><strong>Date</strong></td><td><strong>Count</strong></td></tr>
<tr style="background-color:#ECECEC"><td>2013-03-20</td><td>2113812</td></tr><tr style="background-color:#ECECEC"><td>2013-03-25</td><td>1042</td></tr>

</tbody></table>
</td>
</tr>
</tbody></table>
</body></html>




cell Padding




DateCount
2013-03-202113812
2013-03-251042