Archive

Posts Tagged ‘php’

PHP does 16 years

June 9th, 2011 No comments

of Claudio Garau

PHP, the popular scripting language for Server Side, has made 16 years of life, on 8 June was in fact technologically distant 1995, when the developer Danish Rasmus Lerdorf announcing the birth on USENET. Initially, the acronym does not correspond to the current PHP "PHP: Hypertext Preprocessor” ma a “Personal Home Page”. –> Read full article Html.it

Categories: news, php Tags: ,

How to create a table in PHP in a MySQL database

December 22nd, 2010 No comments

In this article we will see in Php you can create a table in a database MySQL. Before we tackle the config.php file in which there are parameters to connect to MySQL server and the PHP functions for connecting and then tackle the file for table creation, the end of the post you'll find inside the zip with the 2 php file that you can download to do all the tests you want.

Read more…

WordPress: Change the plugin Transposh for machine translation

December 17th, 2010 2 comments

In my blog I use the plugin transposh for machine translation of the homepage, posts and pages. I was going to that side of the flags on the home page appeared the words Edit Translation I wanted to hide so I decided to put his hands directly in the php code of the plugin.

I modified the file that is transposh_widget.php / wordpress / wp-content / plugins / Transposh-translation-filter-for-wordpress / wp transposh_plugin_widget class and I changed the function transposh_widget($args) commenting on this piece of code:

 // add the edit checkbox only for translators for languages marked as editable
 // if ($this->transposh->is_editing_permitted()) {
 //     echo '<input type="checkbox" name="' . EDIT_PARAM . '" value="1" ' .
//      ($this->transposh->edit_mode ? 'checked="checked"' : '') .
//      ' onclick="this.form.submit();"/>&nbsp;Edit Translation';
//}

[UPDATE]
Speaking in the comments with the creator of the plugin Ofer Wald, I discovered that you could do it all without touching a line of code. Going into Settings-> Settings Transposh and setting in Transalation, l’opzione Who can translate ? Administrator and not only for Anonymous.

WordPress: personalizing the quickpress Board

December 17th, 2010 No comments

When I get ideas for new topics and post them to me for my blog just to save a draft through the area quickpress Board of wordpress.

Recently I happened by mistake instead of clicking the button Save Draft button cliccatto I shall make public an unfinished article that is only a draft. If someone was reading through my feed or directly on the blog I was a fool.

So I decided to change the area code php wordpress quickpress Board of Public to hide the button and avoid these mistakes in future.

I took the dashboard.php file that is located in the wp-admin includes and function wp_dashboard_quick_press_output() I commented out the code that added the button in this public way:

<!--<span id="publishing-action">
     <input type="submit" name="publish" id="publish" accesskey="p" tabindex = "5" class="button-primary" value="<?php current_user_can('publish_posts') ? esc_attr_e('Publish') : esc_attr_e('Submit for Review'); ?>" />
     <img class="waiting" src ="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" />
</span>-->

I just commented and deleted lines of code in the future so I can re-enable the Publish button. Now there is no danger of failure.

Programming Php: 7 functions that probably have never used

November 30th, 2010 4 comments

When we program in PHP, often we limit ourselves to a limited number of API functions: those common, like print (), header (), define (), isset (), htmlspecialchars (), etc. If there are some features needed, often we write new by making use of these basic components that we know. The API for PHP really offer a lot of features, some useless and some useful, that are rarely used. I searched the features available and I am interested in finding someone that I really need. Here, I share with you my discoveries.

1. sys_getloadavg ()
sys_getloadvg () is a function that returns three measures “load” its a system. The load is the number of processes in run queue system. In 3 elements of the matrix are the average load for the last 1, 5 and 15 minutes.

1
2
3
4
5
$load = sys_getloadavg(),
the ($load[0] > 80) {
    header('HTTP/1.1 503 Too busy, try again later ');
    the('The server is busy later. Please try again '.);
}

Rather than have the Web service is no longer available (offline) simply because everything fell apart after too many requests received, This code will proactively to accept some requests and denied others. But this code does not work on Windows.

2. cal_days_in_month ()
cal_days_in_month () returns the number of days in a given month:

1
2
$days = cal_days_in_month(CAL_GREGORIAN, date("m"), date("And")); / / 31
echo($days - data("D") + 1 )."Days until".date("F", mktime(0, 0, 0, data("m") + 1, 1, 1970));

3. get_browser ()
Would not it be nice to discover what can make a user's browser before sending the page? Well, you can with get_browser (). You will need to first php_browscap.ini, browscap directive and point to the file. You could have something like this:

1
2
3
$browser = get_browser(null, true);
if(!$browser["frames"] | | !$ browser[Cookies"])
      echo "Please update your browser or use a more modern browser and have cookies enabled because some sections of this site may be inaccessible";

This is not able to detect individual configurations of browser, However,, can not be used to detect if JavaScript is enabled, for example. This feature can be useful to know which browser you use and which platform is used.

4. debug_print_backtrace ()
It can be very difficult to track down a bug in the code, in particular when looking for a logic error, but thanks to debug_print_backtrace() would be much easier. Such as:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$a = 0; 
 
function iterate() 
{ 
      global $a; 
      if( $a < 10 ) recur(); 
      echo $a.", "; 
} 
 
function recur() 
{ 
     global $a; 
     $a++; 
     // how did I get here? 
     echo " \n \n \n "; 
    debug_print_backtrace(); 
    if ( $a < 10 ) iterate (); 
}   
 
iterate (); 
# OUTPUT: #0 recur() called at [C:\htdocs\php_stuff\index.php:8] #1 iterate() called at [C:\htdocs\php_stuff\index.php:25] #0 recur() called at [C:\htdocs\php_stuff\index.php:8] #1 iterate() called at [C:\htdocs\php_stuff\index.php:21] #2 recur() called at [C:\htdocs\php_stuff\index.php:8] #3 iterate() called at [C:\htdocs\php_stuff\index.php:25] #0 recur() called at [C:\htdocs\php_stuff\index.php:8] #1 iterate() called at [C:\htdocs\php_stuff\index.php:21] #2 recur() called at [C:\htdocs\php_stuff\index.php:8] #3 iterate() called at [C:\htdocs\php_stuff\index.php:21] #4 recur() called at [C:\htdocs\php_stuff\index.php:8] #5 iterate() called at [C:\htdocsphp_stuffindex.php:25] [ ... ]

5. natsort()
natsort() is a function that sorts an array of elements in a natural way (ie, in an order that seems logical to a person), rather than a kind of alphabetical order. Take, for example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
$items = array("100 apples", "5 apples", "110 apples", "55 apples");
 
/ / normal order:
black($items);
print_r($items);
 
# The result:
Array #
# (
# [0] => 100 apples
# [1] => 110 apples
# [2] => 5 apples
# [3] => 55 apples
#)

natsort($items);
print_r($items);
 
# The result:
# Array
# (
# [2] => 5 apples
# [3] => 55 apples
# [0] => 100 apples
# [1] => 110 apples
#)

6. Levenshtein()
Levenshtein() is a feature that helps you find the best similarity between 2 words. Let, for example, the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$dictionary = array( "Php" , "Javascript" , "Css" ); 
$word = "japhp"; 
$best_match = $dictionary[0]; 
$match_value = levenshtein ($dictionary[0] , $word); 
 
foreach($dictionary as $in) 
{ 
     $value = levenshtein($word , $in); 
     if( $value < $match_value) 
     { 
          $best_match = $in; 
          $match_value = $value; 
     } 
} 
 
echo "Did you mean the category ' $best_match ' ?";

In this case, the user was asked to provide a category name. Wrote “japhp”, that is not valid. Since this is likely to be a typo, With this feature we can find the category most similar (“Did you mean category ‘php’?”).

7. globe()
globe() , will make you feel stupid after using opendir(), readdir() e closedir() look for a file. The procedure is simple:

1
2
foreach (globe("*. php") as $file)
    echo "$ file n";

More?
There are a lot of useful functions and unknown out there as http_build_query(), register_shutdown_function() e pspell_suggest, what are your favorite?

Source: infinity-infinity.com

Categories: php, Programming Tags: ,