WebDev: JavaScript equivalent of PHP explode function
Dear Publisher,
You can publish this article wherever you feel like, as long as you use the resource box. Although it is not necessary to inform me, but I feel happy if some tell me that my article has been posted :-)
-- Amrit
==========================================
Article Title: JavaScript equivalent of PHP explode function
Category: WebDev
Copyright © 2005 Amrit Hallan
==========================================
== Article Begins ==
In PHP we can easily break a long string into smaller parts by using the explode() function of PHP. In run rime, this function works like this:
== code begins ==
$longstring="Most of the time Amrit is confused -- OK, not most of the time";
$brokenstring=explode(" ", $longstring);
== code ends ==
After the execution of the second command the variable $brokenstring is an array such that,
$brokenstring[0]="Most"
$brokenstring[1]="of"
$brokenstring[2]="the"
$brokenstring[3]="time"
$brokenstring[4]="Amrit"
$brokenstring[5]="is"
$brokenstring[6]="confused"
and so on. So how do we do it in JavaScript. In JavaScript there is a split() function that achieves the same objective, although the syntax is a bit different.
== code begins ==
var longstring="Most of the time Amrit is confused -- OK, not most of the time";
var brokenstring=longstring.split(" ");
== code ends ==
Now the variable brokenstring has all those words.
== Article Ends ==
About the author:
===============================================
Amrit Hallan is a freelance copywriter,
and a website content writer. He also dabbles
with PHP and HTML. For more tips and tricks in
PHP, JavaScripting, XML, CSS designing and
HTML, visit his blog at
www.aboutwebdesigning.com
===============================================
|