RSS

Monthly Archives: November 2010

Override PHP Function

PHP have PECL (PHP Extension & Community Library) function to override built-in functions by replacing them in the symbol table.

bool override_function ( string $function_name , string $function_args , string $function_code )

  1. <?php
  2. override_function(‘strlen’, ‘$string’, ‘return override_strlen($string);’);
  3. function override_strlen($string){
  4. return strlen($string);
  5. }
  6. ?>

The above function “override_function()” require APD i.e. Advanced PHP Debugger.

We can find more about APD here…
http://pecl.php.net/package/apd

Linux users can install apd using below command

# pecl install apd

There is an alternate way to override PHP functions, we can use below class “override” to override any built-in PHP function if PECL is not installed on server 😉

  1. <?php
  2. $or = new override ();
  3. $or->override_function(‘strlen’, ‘override_strlen‘, ‘return override_strlen($string);’);
  4. function override_strlen($string){
  5. return strlen($string);
  6. }
  7. ?>

<?php


$url = 'http://www.svnlabs.com';
$override = new override();

$override->override_function('file_get_contents','fileGetContents',$url);

if ($over_func_name = $override->override_check('file_get_contents')) {
    $result=call_user_func($over_func_name, $url);
}

function fileGetContents($url)
{
  /// statements
}

?>

PHP Function OverRide Class

  1. <?php
  2. class override {
  3. var $functions = array();
  4. var $includes = array();
  5. function override_function($override, $function, $include) {
  6. if ($include) {
  7. $this->includes[$override] = $include;
  8. }
  9. else if (isset($this->includes[$override])) {
  10. unset($this->includes[$override]);
  11. }
  12. $this->functions[$override] = $function;
  13. }
  14. function override_check($override) {
  15. if (isset($this->includes[$override])) {
  16. if (file_exists($this->includes[$override])) {
  17. include_once($this->includes[$override]);
  18. }
  19. if (function_exists($this->functions[$override])) {
  20. return $this->functions[$override];
  21. } else {
  22. return false;
  23. }
  24. } else {
  25. return false;
  26. }
  27. }
  28. }
  29. ?>

Make a habit of creating things modular, that means “pluggable” and “unpluggable”.

<?php
class override {
var $functions = array();
var $includes = array();
function override_function($override, $function, $include) {
if ($include) {
$this->includes[$override] = $include;
}
else if (isset($this->includes[$override])) {
unset($this->includes[$override]);
}
$this->functions[$override] = $function;
}
function override_check($override) {
if (isset($this->includes[$override])) {
if (file_exists($this->includes[$override])) {
include_once($this->includes[$override]);
}
if (function_exists($this->functions[$override])) {
return $this->functions[$override];
} else {
return false;
}
} else {
return false;
}
}
}
?>


 
2 Comments

Posted by on November 23, 2010 in CakePHP, Open Source, PEAR, php, Tips, Tricks

 

Tags: , , , , ,

Web scraping using firefox & jQuery

Hello Friends,

Today we will scrape HTML from any web page using jQuery and firefox firebug console. This is useful when you want to grab HTML of web page dynamically created by JavaScript or Ajax.

This example is quite useful when you want to extract any web content based on HTML Tag element ID or Class like ‘<div id=”svnlabs”></div>’ or ‘<img src=”svnlabs.jpg” id=”svn_labs”>’

See the code in action here… scraper.txt

jQuery(“body”).append(‘<textarea id=”svnlabs” cols=”70″ rows=”20″></textarea>’);

jQuery(“#svnlabs”).val(jQuery(“body”).html());

OR

copy and paste below code in browser address bar….

javascript: jQuery(“body”).append(‘<textarea id=”svnlabs” cols=”70″ rows=”20″></textarea>’); jQuery(“#svnlabs”).val(jQuery(“body”).html());

You have to post above code in firefox firebug javascript console. The latest jQuery library must be included on that web page you want to scrap 😉
Above two JavaScript lines will add a new textarea in body of same web page to set content of any HTML element. Please make sure after copy the above code; no illegal character in it.

Keep blogging……… 😉

 
13 Comments

Posted by on November 18, 2010 in javascript, Launch, Open Source, Tips, Tricks

 

Tags: , , , , , , ,

Open source – Port25

If you have trouble getting the PHP’s mail() function to work on your server.
If the function returned true, but never send the emails to target account.
Some ISP’s block port 25 (mail port), so you can’t send directly but you can send indirectly using your ISP’s mail server. 😉

Many email providers keep lists of IP addresses and block incoming mail, or move it immediately to a junk/spam folder.

There are some Open Source solutions to filter your mail problems..
You can check Open Source MTA here http://en.wikipedia.org/wiki/Comparison_of_mail_servers

Here list some MTAs as

  1. postfix
  2. qmail
  3. exim
  4. sendmail

Above MTA don’t handle integrated reporting, bounce management, and spam management, reporting.

PowerMTA: PowerMTA (this is not open source) provides the unique features and capabilities required by email service providers and enterprises to maximize the effectiveness of email marketing and customer communications, handle integrated reporting, bounce management, and spam management, reporting etc.

http://www.port25.com/products/prod_features.html

 

Tags: , , , , , , , , ,

Wishing you a very HAPPY DIWALI!

http://www.youtube.com/v/RZK0rDJcXz8?fs=1&hl=en_US&rel=0&color1=0x5d1719&color2=0xcd311b

The happiest of wishes for a Deepawali, that will be happy in every way for someone like you.

Fortunate is the one who has learned to Admire, but not to envy.
Good Wishes for a joyous Diwali and a Happy New Year with a plenty of Peace and Prosperity.

Happy Diwali

 
Leave a comment

Posted by on November 4, 2010 in Launch

 

Tags: , , ,