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 = “07/31/2010″;

 

- 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 = 07
$day = 31
$year = 2010

 

- 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 3 votes.
 
Rate This Page;

 

 

Comment? »

 

 

Leave a comment
 

 Name (required)

 E-mail (required,not published)

 URI

 

 

 

 
 

Advertisements
 
Must clicks!

lady
 
ajwa . Naj . Wawa . 26 . . 290 days until my 27th 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,
342382 were all cried out,
Since 29-Jan-2006

Powered by  MyPagerank.Net

 

random links
 
Ayu The Sun
Megat Eusofe
Mell's Delite
I'm Just A Boy Next Door
Deida
Duke Luce Dell'amore
Adie Waridi
Sultan Muzaffar
The Sweet Escape of Lyn Yusoff
Anis Hayati's Life
Contagious.nu
Joe Klubbkidd
Yoyooh.com
WhatYouSee.Co.Nr
Magazine Junkie
AfiqHakim.com
Sky-Reflection.com
MartiniStyle.net
Saffawati.com
Nadia-Haswani.com

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.
* * * * * * * * * * * * *