Wednesday, September 14, 2011

WordPress And PHP Global Variables Problem

Does WordPress Control Global Variables in a Different Way?
Wordpress And PHP Global Variables Problem

Today I have found a new unusual problem of PHP global variables in WordPress. ( It may be my problem). I was trying to change the wp global variable $current_user in a user define function by calling global keyword. My code was
<?php
function add_some_user_info()
{
global $current_user; #Global Variable Generated By WP Core
 $current_user->new_info="My New Value"; # Remember this line

}
 add_some_user_info();
echo "<pre>";print_r($current_user);echo "</pre>";
?>
Output: Showing WP current user object with my additional Value.
When I use   $current_user="Test Value"; Output: Test Value
When I use $current_user=false or null or 0; Output should be  blank but it is showing WP current user object without no change. That means I can not change $current_user object to delete, null, false or zero but can change with some string.  How it works?
Then I guessed that $current_user variable may be protected by a different way.(What is the technique?)

I tested the following codes to identify the PHP Global variable rule.
<?php
$test="<br>First Value<br>";
function test_function()
{
global $test;
echo $test;
$test="<br>Second Value Changed by Function<br>";
}
test_function();
echo "<pre>";print_r($test);echo "</pre>";
?>
I wrote the above code in a normal.php file and run it.
Output:
First Value
Second Value Changed by Function
---------------------

Then I wrote the same code beginning of   a WordPress theme file header.php and run it.

Output:
First Value
-------------- 

Why these different output  in   normal.php file and wordPress header.php file ?

If anybody confused about my words test my codes in a simple file and a WP theme file.
Have You Any Correct Explanation About This Problem?

Tuesday, August 23, 2011

Google Plus API is Coming Very Soon for Developers

Google is rolling out API very soon for developers to take a sneak peak and develop applications. In the meantime developers can sign up at https://services.google.com/fb/forms/plusdevelopers/ to get a early access onto the Google plus API.

Wednesday, July 27, 2011

HSC Result 2011 From An Alternative Faster Server | Education Board Bangladesh


Today Ministry of Education Board Published The HSC Result 2011. The Main Result Publishing Site of Education Board Bangladesh is educationboardresults.gov.bd. But this site is too slow and busy today and you are unable to see the result.
I have made an alternative server to search the HSC Result 2011. My search result is also coming from educationboardresults.gov.bd.

Go to Our Alternative Server 1 to Search HSC Result 2011 »»


Go to Our Alternative Server 2 to Search HSC Result 2011 »»



HSC Result 2011 | Education Board Bangladesh | An Alternative Server


Thursday, June 23, 2011

Microdata Format | New HTML Schema by Google, Microsoft, and Yahoo!

Most webmasters are familiar with HTML tags on their pages. Usually, HTML tags tell the browser how to display the information included in the tag. For example, <h1>Avatar</h1> tells the browser to display the text string "Avatar" in a heading 1 format. However, the HTML tag doesn't give any information about what that text string means—"Avatar" could refer to the a hugely successful 3D movie, or it could refer to a type of profile picture—and this can make it more difficult for search engines to intelligently display relevant content to a user.
Schema.org provides a collection of shared vocabularies webmasters can use to mark up their pages in ways that can be understood by the major search engines: Google, Microsoft, and Yahoo!
You use the schema.org vocabulary, along with the microdata format, to add information to your HTML content. While the long term goal is to support a wider range of formats, the initial focus is on Microdata. This guide will help get you up to speed with microdata and schema.org, so that you can start adding markup to your web pages. Read Detail on schema.org

Monday, May 9, 2011

How to remove whitespace or any characters from beginning or end of a string in PHP?

Today I have faced a problem to remove extra forward slash ( / ) from a URL. I was working with some string manipulation operations. I need to parse some URL programmatically. At first I have to confirm that there is no extra forward slash end of the URL. If my url is like http://example.com/php/ . First I need to make this to http://example.com/php. I know the PHP function trim() but it  Strip white space and some other characters ( \n \t \r \0 \x0B and given character) from the beginning and end of a string. But I have to remove only  from end of the string not from beginning. At last I have found another related PHP function rtrim(). I have also learn the function ltrim(). Here I am describing these three trimming functions.

trim() : Strip whitespace (or other characters) from the beginning and end of a string
ltrim() :
Strip whitespace (or other characters) from the beginning of a string
rtrim() : Strip whitespace (or other characters) from the end of a string

Functions Prototypes:

string trim ( string $str [, string $charlist ] )
string ltrim ( string $str [, string $charlist ] )
string rtrim ( string $str [, string $charlist ] )

These three function has two same parameters and same return type. First parameter is required and second is optional.
These functions return a string with whitespace stripped from the end and beginning or only end or only beginning of the given string.
Without the second parameter these functions will remove following  characters:
  • " " (ASCII 32 (0x20)), an ordinary space.
  • "\t" (ASCII 9 (0x09)), a tab.
  • "\n" (ASCII 10 (0x0A)), a new line (line feed).
  • "\r" (ASCII 13 (0x0D)), a carriage return.
  • "\0" (ASCII 0 (0x00)), the NUL-byte.
  • "\x0B" (ASCII 11 (0x0B)), a vertical tab.
You can also specify the characters you want to strip, by means of the charlist parameter. Simply list all characters that you want to be stripped. With .. you can specify a range of characters. 
Trims occurances of every word in an array from the beginning and end of a string + whitespace and optionally extra single characters as per normal trim().

What is the different between  tirm() ltrim() and rtrim():

trim() is remove chars from both  left and right side of a string. You can use it to clear the white spaces some special chars and your defined char from both side of user inputted text. But if you need to clear only one side , then you should use ltrim() for left side and rtrim() for right.
My problem was to clear "/" only from right side of URL . I used rtrim();

Example of my use:

<?php
$url="http://example.com/php/class1/";
$newurl=rtrim($url, "/");
echo $newurl;   
?>

Another Example:

<?php

$text 
"\t\tThese are a few words :) ...  ";

$binary "\x09Example string\x0A"; 
$hello  "Hello World"; 
var_dump($text$binary$hello);

print 
"\n";
$trimmed rtrim($text);

var_dump($trimmed);
$trimmed rtrim($text" \t."); 

var_dump($trimmed);
$trimmed rtrim($hello"Hdle");

var_dump($trimmed);
// trim the ASCII control characters at the end of $binary
// (from 0 to 31 inclusive)
$clean rtrim($binary"\x00..\x1F"); 

var_dump($clean);

?>


OutPut:

string(32) "        These are a few words :) ...  "
string(16) "    Example string
"
string(11) "Hello World"

string(30) "        These are a few words :) ..."
string(26) "        These are a few words :)"
string(9) "Hello Wor"
string(15) "    Example string"

While inserting data from web forms to databases, trimming the posted values to remove the spaces from the left and right sides can be a good idea to avoid the user faults. This code have to be located before the DB operations

This post is the answer of the following questions and queries

  • How can i remove white space from the beginning of a string?
  • How can I clean extra # $ % ^ * @ or any given character from the end of line
  • How can I confirm whether the last char of a URL is a "/"
  • How to clean the left side of a string?
  • How to clean the right side of a string?
  • How to trim a string?
  • What are the different between all PHP trimming function?
  • PHP trim functions
  • PHP strip functions
  • PHP string cleaner functions
  • Trim Left Trim and Right Trim
  •  The simplest way to strip a newline form a text file is ltrim()
  • To remove an unwanted character - example "." - if exist or not
  • PHP tutorial for string trimming.


New Design of Google Search Result Page is Coming Soon


Google has decided to change their search result page design. They already has made new design and it is steel testing. New design is running but it is being shown only for some special region and special person.

What is new in new design:
  1. Result title font size has been increased
  2. Distance between two result is higher than old version
  3. Snippets (descriptions) are shown in one line, maximum two lines.
  4. Real time contents get priorities, for that reason twitter is being come top
  5. Overall look is fresher than previous

Some Screen shorts  of New Search Result Page:





Trackback