Very short trick: 3 output function in PHP
Tuesday, 18 November, 2008Within a PHP function you can print in three different ways:
- <? php
- $valore = 'Ciao' ) { miaFunction function ($ value = 'Hello') (
- >
- <ul>
- <li> <? = $ value> </ li>
- </ ul>
- <? php
- )
- >
Or:
- $valore = 'Ciao' ) { miaFunction function ($ value = 'Hello') (
- . $valore . '</li></ul>' ; $ o = '<ul> <li>'. $ value. '</ li> </ ul>';
- )
Or:
- $valore = 'Ciao' ) { miaFunction function ($ value = 'Hello') (
- ; $ o = "<ul> <li> $ value </ li> </ ul>";
- )
Related Post
Actionscript 3.0 for beginners: lesson # 4
Tuesday, 11 November, 2008Resume our sample code of TicTacToe (which is entirely on Google Code) and we start to analyze it in detail.
Import definitions
With Actionscript 3.0 has been done a great job of cleaning and arrangement of classes nell'alberatura (contained in the package package) used during development. In other programming languages, like C for example, when you want to use a feature must explicitly "import" in the code. This operation "import" is necessary to allow the compiler to have all the codes and definitions related features that we want to use. In Actionscript 3.0, however, Education import should not be confused with the standard C / C + #include # #include Actionscript 3.0 provides education include that is identical to #include the C / C + +. The latter include "actual code that, if used or not, is compiled into the final. Education import is the highest level and is more "intelligent" being compiled. It serves primarily to access classes without having to specify the full name. In Alré words instead of using forms like this:
- . MovieClip = new flash. display . MovieClip ( ) ; var myMC: flash. display. MovieClip = new flash. display. MovieClip ();
Related Post
Wordpress: remove the menu
Saturday, November 1, 2008 It may be useful, sometimes, "obscure" some of the menu of Wordpress, especially if you developed a website / blog for a client and do not want to allow access to sensitive features. There Plugin already performing this function, but to have a personal and complete control, we see in detail how this feature.
As always exploit the useful Action made available by Wordpress, in this case admin_menu Through the global variable $menu can access the list of the menu. We can find the menu to "remove" in two ways: through the label or via the link that it points (see commented shares in the example below). The proposal is "obscured" menu items Design, Settings and Plugins:
- remove_menu_item function () (
- / / By label
- / / Through links
- / / $ Removes = array ( 'themes.php', 'options-general.php', 'plugins.php');
- $removes as $todel ) foreach ($ removes as $ todel)
- / / Through links
- / / Foreach ($ menu as $ key => $ sm) if ($ sm [2] == $ todel) (unset ($ menu [$ key]); break;)
- )
- / /
- , 'remove_menu_item' ) ; add_action ( 'admin_menu', 'remove_menu_item');
Using the links as key to the removal $sm[2] in parts commented code surprise here), is useful when there is certainty of language - location - with which you installed Wordpress. With this technique, however, the menu is removed only at the interface, so you can still access the page via a direct link.
Related Post
Wordpress: write a personal logout
Monday, October 27, 2008 Starting from post Wordpress: step by step how to create a login, performed the login procedure could be useful to indicate in our blog a link to the disconnection, or logout. We will not use again the standard procedures of Wordpress, but we'll see how to log out low level. First of all we must understand whether a user is logged on or not. This is possible simply querying the variable $user_ID of Wordpress. For example:
- $user_ID != '' ) { // oppure if( is_user_logged_in() ) { if ($ user_ID! ='') (/ / or if (is_user_logged_in ()) (
- / / User is "logged" ...
- )
Once we know that a user is logged in the system, we can insert a simple link to our page logout. Then we create a page, for example logout.php and inserting the following code:
- / **
- * Performs logout
- *
- * @ Author Giovambattista Fazioli
- * @ @ Email g.fazioli undolog.com
- * @ Web http://www.undolog.com
- * /
- / / Invoke WordPress bootstrap
- 'wp-config.php' ) ; @ Require_once ( 'wp-config.php');
- 'wp-includes/pluggable.php' ) ; @ Require_once ( 'wp-includes/pluggable.php');
- / / Wp logout
- wp_logout ();
- / / Load any other page
And just then "link" to our page to provide a logout procedures:
- $user_ID != '' ) { if ($ user_ID! ='') (
- ; echo 'Run the <a href="logout.php"> logout </ a>';
- )
Related Post
FireFox: management profiles
Thursday, October 23, 2008Mozilla Firefox lets you manage multiple profiles, features useful to those who, like me, develops Web sites and requires a series of extensions dedicated to debug and analysis of Web pages. Through the use of profiles you can configure different settings FireFox:
Firefox save your personal information such as bookmarks, passwords and preferences in a file called profile in a different location than the program files for Firefox.
On Windows Vista (see here for other operating systems) allows access to management profiles from Esegui command using:
- firefox-ProfileManager
One of the advantages in the use of profiles is to have a FireFox to navigate, without any toolbar and extensions for debugging and FireFox to develop, together with Firebug and all other development tools.
Related Post
Very short trick: undefined values in Javascript
Wednesday, 22 October, 2008There is an abbreviated form for assigning "in flight" a value to a variable if another is not defined (undefined), using the logical OR operator (| |) - Double-pipe:
- / / Pluto is undefined
- var pluto;
- ; var foo = pluto | |'5 ';
- pippo ) ; alert (foo);
- / / Result: 5
This technique is useful for writing functions with parameters:
- param ) { miaFunc function (param) (
- ; var p1 = param | | 'benchmark';
- / / ...
- )
But we must be careful to use this form as zero values such as 0 false are misinterpreted, because of "guilt" of the OR logic used:
- ; pluto var = 0;
- ; var foo = pluto | |'5 ';
- pippo ) ; alert (foo);
- / / Result: 5
- ; pluto var = false;
- ; var foo = pluto | |'5 ';
- pippo ) ; alert (foo);
- / / Result: 5
- ; pluto var = 1;
- ; var foo = pluto | |'5 ';
- pippo ) ; alert (foo);
- / / Result: 1
Related Post
Variety of coding and coding
Tuesday, October 14, 2008Someone argues that programming is an art and, ultimately, I can only agree especially when solutions are found very different for the same problem. To understand how true this is like an identical need in medisimo language (Javascript) can be resolved with approaches quite different and original.
Left zero Pad
A number, but the speech is also valid for any string, such as 123 can be filled on the left - to draw - with a number of zeros, for example: 00123 This need is presented on several occasions and is useful for aligned - or show - a number cleanly, implicitly indicating its maximum value. In the video, for example, the classic score (the score) is often indicated by 001234 indicating that at most it comes to 999999 Here's how the problem was solved by various developers:
- / **
- * Left Pad String
- *
- * @ From http://snipplr.com/view/8423/left-pad-string/
- * @ Author web-http://www.mechanicmatt.com/
- *
- * @ Param num - to fill Striga
- * @ Param totalChars - Total number of characters, including the "zeros"
- * @ Param padWidth - Character used to fill, default "0"
- * /
- num, totalChars, padWith ) { leadingZeros function (num, totalChars, padWith) (
- num num + = "";
- ? padWith = (padWith)? padWith: "0";
- num. length <totalChars ) { if (length internal reference number <totalChars) (
- num. length <totalChars ) { while (length internal reference number <totalChars) (
- padWith + num = num;
- )
- { } Else ())
- num. length > totalChars ) { //if padWith was a multiple character string and num was overpadded if (length internal reference number> totalChars) (/ / if padWith was a multiple character string and num was overpadded
- num. length - totalChars ) , totalChars ) ; = num num. substring ((internal reference number length - totalChars), totalChars);
- { } Else ())
- return num;
- )
- leadingZeros ( "asdf" , 10 , "0" ) ) ; alert (leadingZeros ( "asdf", 10, "0"));
This solution is extremely articulate, but can add an indefinite number of 0 number num also choosing the font used by padWidth instead of the default 0
Definitely original, however, this solution:
- / **
- * String_pad
- *
- * @ From http://snipplr.com/view/700/stringpad/
- * @ Author http://d.hatena.ne.jp/brazil/20060721/1153489937
- *
- * @ Param str - to fill Striga
- * @ Param len - Total number of characters, including the "zeros"
- * @ Param ch - Character used to fill
- * /
- str, len, ch ) { return new Array ( len- ( '' +str ) . length + 1 ) . join ( ch ) + str } function pad (str, len, ch) (return new Array (len-(''+ str). length + 1). join (ch) + str)
- pad ( 56 , 4 , '0' ) ) ; // 0056 alert (pad (56, 4,'0 ')); / / 0056
Same result, with a completely different approach. Again we have the opportunity to decide the number of characters padding through the parameter len and the font used by ch Fails to use the default provided in the previous function.
What I use instead ...:
- / **
- * String_pad
- *
- * @ Author Giovambattista Fazioli
- * @ Web http://www.undolog.com
- *
- * @ Param s - to fill Striga
- * @ Param l - A string that indicates the character is that the length
- * Such as "0000" character = "0" length 4
- * /
- s,l ) { return ( l. substr ( 0 , ( l. length -s. length ) ) +s ) ; } padding function (s, l) (return (l. substr (0, (l-s length. length)) + s);)
- padding ( '123' , '0000' ) ) ; alert (padding ('123 ','0000'));
If you have other interesting solutions please comment ![]()
Related Post
A class countdown in Javascript
Monday 13 October, 2008In the post with 3D CountDown FIVe3D (See How I Did It: write a countdown in Flash), was a class proposal for the creation of an object CountDown in Actionscript, here's a version similar in Javascript:
- / **
- * CountDown Class
- *
- * @ Author Giovambattista Fazioli
- * @ @ Email g.fazioli undolog.com
- * @ Web http://www.undolog.com
- *
- * @ Param dd (string) 'day month, year'
- *
- * /
- dd ) { function countdown (dd) (
- / / Init target time
- Date ( dd ) ; var target = new Date (dd);
- = target. getTime ( ) ; this. targetTime = target. getTime ();
- / **
- * Refresh countdown
- * /
- = function ( ) { this. refresh = function () (
- Date ( ) ; var today = new Date ();
- ( ) ; var = currentTime today. getTime ();
- / / Time left
- this . targetTime - currentTime ) ; this. _leftMilliseconds = (this. targetTime - currentTime);
- ( this ._leftMilliseconds / 1000 ) ; this. _leftSeconds = Math. floor (this. _leftMilliseconds / 1000);
- ( this ._leftSeconds / 60 ) ; this. _leftMinutes = Math. floor (this. _leftSeconds / 60);
- ( this ._leftMinutes / 60 ) ; this. _leftHours = Math. floor (this. _leftMinutes / 60);
- / / No module
- = Math. floor ( this ._leftHours / 24 ) ; this. leftDays = Math. floor (this. _leftHours / 24);
- / / For print
- = this ._leftMilliseconds % 1000 ; this. leftMilliseconds = this. _leftMilliseconds% 1000;
- = this ._leftSeconds % 60 ; this. leftSeconds = this. _leftSeconds% 60;
- = this ._leftMinutes % 60 ; this. leftMinutes = this. _leftMinutes% 60;
- = this ._leftHours % 24 ; this. leftHours = this. _leftHours% 24;
- )
- ( ) ; this. refresh ();
- )
Example
- countDown ( '1 1, 2009' ) ; var so = new countdown ('1 1, 2009 ');
- / / Show how many days, hours, minutes, seconds and milliseconds in the first January 2009
- cd. leftDays + "," + cd. leftHours + "," + cd. leftMinutes + "," + cd. leftSeconds + "," + cd. leftMilliseconds ) ; document. write (ie leftDays + "," + cd. leftHours + "," + cd. leftMinutes + "," + cd. leftSeconds + "," + cd. leftMilliseconds);
Related Post
Very short trick: avoid error message in PHP
Wednesday, October 8, 2008If we do not want a PHP issue any error or warning, just enter the first call to the function of the snail - or at - (@):
- / / Instead of using the canonical form
- ; $ res = miaFunc ();
- / / You can use
- ; $ res = @ miaFunc ();

















