Tutorial: PHP
Split String
 

Ever wanted to split a string into array by reqular expression? For example, you can use this function to parse a spring of date into month, day, and year that’s delimited with slashes, dots, or hyphens. Here’s a basic way to do it.

 

- For instance, I have captured today’s date as the following;

$date = “02/09/2012″;

 

- To do the splitting, you will need to use these list and split function;

list($month, $day, $year) = split(‘/’, $date);

 

- The $month, $day, and $year variables are used to store the splitted date. The ‘/’ is the delimiter that will act as a boundary to split the date. The delimiters may be slash, dot, or hyphen. But you may also use them all at the same time too;

list($month, $day, $year) = split(‘[/.-]‘, $date);

 

- And as the result, you will get the following;

$month = 02
$day = 09
$year = 2012

 

- And of course you may retrieve those variable by using this piece of code;

<?php echo $month?>
<?php echo $day?>
<?php echo $year?>

 

- And oh, take a note that some delimeters will need some exception. For example… symbol “?” and “|” alone will not work, because they are operators in PHP. So if you want to use those symbols as delimiter you must excape it with a back slash, “\|“. Your code should look something like this;

list($att1, $att2) = split(‘\?\|’, $string);

 

 

 


 

Avarage Rating:  from 4 votes.
 
Rate This Page;

 

 

Comment? »

 

 

Leave a comment
 

 Name (required)

 E-mail (required,not published)

 URI

 

 

 

 
 

Advertisements
 
Must clicks!

Click Here to Advertise On My Blog
...also get paid to blog!

lady
 
ajwa . Naj . Wawa . 27 . . 98 days until my 28th birthday on May 18th . IT Engineer . Malaysian . Dreamer . Worrier . Simple . Boringgg . but Laughs a lot . Gaining back her self-confidence ♥ Mariah carey . David Archuleta . Michael Bublé . James Morrison . Anuar Zain . Akim . Faizal Tahir . Diddy . Jesse McCartney . Linkin Park . BSB . *N Sync . Rascal Flatts . Smallville . Charmed . One Tree Hill . Merlin . Summerland . The City . Jonas . Matrix Trilogy . LOTR . Star Wars Saga . Twilight Saga . The Covenant . Taylor Lautner . Tom Welling . Paul Walker . Steven Strait . Hugh Jackman . Josh Hartnett . Chad Michael Murray . Ewan McGregor . Natalie Portman . Cameron Diaz

?

playlist cam cam
 
facebook twitter yahoo! messenger youtube

 
Your Text Ads Here?
 

 

navigate
 
Journal
Lady
Artwork
Collective
Visitor
        Graphics
        Downloads
        Scripts
        Reads
        Games
        Interactive
        Tutorial
 
Plugboard
Exits
SecretWhisper

 

skins





skins more?

 

stats
 
7 online currently,
0 cried on this page,
432768 were all cried out,
Since 29-Jan-2006

Powered by  MyPagerank.Net

 

random links
 
Nad The Pinky Gurl
Adie Waridi
Kos Serani
Romi Flizz
Sweet Love From Myra
Arafah98
HeavenLeigh Ann
Linda * Colour of Life
LiLo
Qarl
Letters-To-You.com
CantikCeria.com
Saffawati.com
AndyzWeb
RedMummy.com
Contagious.nu
Joe Klubbkidd
MartiniStyle.net
Nadia-Haswani.com
ItsNerdy.org

link exchanges more?

 

Follow Me


 

etcetera

 

 
Earn Money Online?
Free Domain?
 

 
 Search the web/site.
Web SawYouCry

 

 

© Najwa 2005-08
SecretWhisper Production
All rights reserved.
* * * * * * * * * * * * *