Bansal Sumit on August 25 2010
We’re going to use several string functions together. Let’s take the string testing testing Username:Michele Davis and retrieve only the name.
Using several functions together to extract a portion of a string
$test_string="testing testing Username:Michele Davis";
$position=strpos($test_string,"Username:");
//add on the length of the Username:
$start=$position+strlen("Username:");
echo "$test_string
";
echo "$position
";
echo substr($test_string,$start);
?>
This Code Return
testing testing Username:Michele Davis
16
Michele Davis
Note: The number 16 in our example is the position of our username
Use strpos to search for Username: and return its position in the string with zero being the first position. Use strlen to add on to that position to find where you need to start extracting from the $test_string. To extract the name, use substr, which takes the string as a parameter, returning everything after the $position character in the string.
Filed under PHP Functions
Bansal Sumit on August 25 2010
To detect whether a string is part of another string, use strstr. This function takes two parameters: the string to search through and the string to search for. It is not case sensitive; if you want to use a function that is case sensitive, use stristr. Lastly, there is strops, which finds the position of every first occurrence of the string you specified.
Detecting whether a string is contained in another string
$password="secretpassword1";
if (strstr($password,"password")){
echo('Passwords cannot contain the word "password".');
}
else {
echo ("Password accepted.");
}
?>
This Code Returns: Passwords cannot contain the word “password”.
Filed under PHP Functions
Bansal Sumit on August 25 2010
PHP provides functionality for changing the case of a string to all uppercase, all lowercase, or the first letter of a word to uppercase. The commands are strtoupper, strtolower, and ucwords, respectively.
Using the word case functions
$username="John Doe";
echo("$username in upper case is ".strtoupper($username).".
");
echo("$username in lower case is ".strtolower($username).".
");
echo("$username in first letter upper case is ".ucwords($username).".
");
?>
The above code returns:
John Doe in upper case is JOHN DOE.
John Doe in lower case is john doe.
John Doe in first letter upper case is John Doe.
Filed under PHP Functions
Bansal Sumit on August 25 2010
Filed under PHP Scripts
Bansal Sumit on August 25 2010
The substring functions provide a way to extract a portion of a string. All that’s needed is the string to work with, the position to start from, and how many characters to extract. Use the LEFT, RIGHT, and SUBSTRING functions to do the extraction
LEFT:- Takes the string and the number of characters to extract from the start of the string.
For Example: LEFT(’6128238193′,3)
RIGHT:- Takes the string and the number of characters to extract from the end of the string.
For Example: SUBSTR(’6128238193′,4,3)
SUBSTR:- Takes the string and the number of characters to extract beginning with a certain position in the string.
For Example: RIGHT(’6128238193′, 4)
Adding the formatting to a phone number using LEFT, RIGHT,and SUBSTR
For example: if a database has phone numbers stored in a 10-digit string without any formatting, the numbers could be displayed with the formatting by using the code
SELECT CONCAT('(',LEFT('6128238193',3),')',SUBSTR('6128238193',4,3),'-',RIGHT('6128238193', 4));
These Commands Return: (612)823-8193
Filed under PHP Functions
Bansal Sumit on August 22 2010
Filed under Wordpress Tips
Bansal Sumit on August 22 2010
Update your wordpress old version into current new version
following steps to update your Blog
- Check Requirements
- Take a Backup of Your Database
- Disable Plugins
- Ready to Update
Now that you’ve checked that you’re ready to update, you’ve turned off your plugins and you’ve got your backup, it’s time to get started.
There are two methods for updating – the easiest is the Automatic Update, which will work for most people. If it doesn’t work, or you just prefer to be more hands-on, you can follow the manual update process.
For More Information Click here
Filed under Wordpress Tips
Bansal Sumit on August 12 2010
Filed under Wordpress Tips
Bansal Sumit on August 12 2010
1. Login to your wordpress dashboard.
2. Go to ‘Permalinks’ settings option under ‘Settings’ in left navigation.
3. You can see some common settings there. They are
1. Default
2. Date and Name
3. Month and Name
4. Numeric
5. Custom structure
We will see in detail.
For example, consider my blog www.sumitbansal.com
1. In default my post and page urls will be like this
www.sumitbansal.com/?p=1
2. If you choose Date & Name option, urls will be
http://sumitbansal.com/2009/12/22/paging-in-php-splitting-records-into-pages/
3. If you choose Month & Name option urls will be
http://sumitbansal.com/2009/12/paging-in-php-splitting-records-into-pages/
4. If you choose Numeric, it will be like this
http://sumitbansal.com/archives/123
5. The last one is custom structure option. You can use this to
Customize your URL structure.
Filed under Wordpress Tips
Bansal Sumit on August 11 2010
Filed under PHP Scripts