Retrieving a protected page with HTTP_Request

<?php $r = new HTTP_Request(’http://www.w3mentor.com/protect.php’); $r->setBasicAuth(’username’,’password’); $r->sendRequest(); $page = $r->getResponseBody();
Continue reading…

Enjoyed this post? Share it!

 
 

PHP Validate Email – String Function

<?php function validate_email($email) { $regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,6})$"; if (eregi($regexp, $email)) return 1; else return 0; } if (isset($_POST[’submit’])){ echo "Hi ".$_POST[’name’]."!<br />"; if (validate_email($_POST[’email’])) echo "The address ".$_POST[’email’]." is valid!"; else echo "The address <strong>".$_POST[’email’]."</strong> is invalid!"; } ?><form action="index.php" method="post"> Name:<input type="text" name="name" value="" /> Email Address:<input type="text" name="email" value="" /> <input type="submit" name […]
Continue reading…

Enjoyed this post? Share it!

 
 

PHP Find Weekday – String Function

<?php function find_weekday($month, $year, $weekday, $offset=1) { $month_ts = strtotime("$year-$month-01"); if(–$offset > 0) $month_ts = strtotime("+$offset week", $month_ts); $month_ts = strtotime($weekday, $month_ts); return $month_ts; } echo date(’d M Y’, find_weekday(5, 2000, "Friday")) . "<br />"; echo date(’d M Y’, find_weekday(5, 2000, "Friday", 1)) . "<br />"; echo date(’d M Y’, find_weekday(5, 2000, "Fri", 2)) . […]
Continue reading…

Enjoyed this post? Share it!

 
 

PHP Using Preg_Replace_Callback() To Replace Patterns – String Function

  preg_replace_callback() allows you to assign a callback function. preg_replace_callback() requires a regular expression, a reference to a callback function, and the string to be analyzed. <? function convDate( $matches ) { $year = ($year < 70 )?$matches[3]+2000:$matches[3]; $time = ( mktime( 0,0,0,$matches[1],$matches[2],$matches[3]) ); return date("l d F Y", $time); }$dates = "3/18/03<br />\n7/22/04"; $dates […]
Continue reading…

Enjoyed this post? Share it!