Identify how many coma are there
Moderator: General Moderators
Identify how many coma are there
i wonder if there is a function to count how many coma are there in a string ??
vb has function such as instr, left and right. Are there any in php ???
how can i split a string eg
"today is sunny*today is raining^today is cloudy"
into
"today i sunny"
"today is raining"
"today i cloudy"
help is greatly appreciated. thanks.
vb has function such as instr, left and right. Are there any in php ???
how can i split a string eg
"today is sunny*today is raining^today is cloudy"
into
"today i sunny"
"today is raining"
"today i cloudy"
help is greatly appreciated. thanks.
- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
well with that string you could do
but if its just commas that would be a whole lot easier
Code: Select all
$first = explode('*', $string);
$second = explode('^', $first[1]);
$arr[] = $first[0];
$arr[] = $second[0];
$arr[] = $second[1];
print_r($arr);-
thegreatone2176
- Forum Contributor
- Posts: 102
- Joined: Sun Jul 11, 2004 1:27 pm
Code: Select all
header(11/02/2004,4.00,Carpark).
present(bish tan,sarene tan,carlo pun).
absent(rezoto ng,jackie tan).
apology(willy chan, carment ng).
% discussion
point(1, [
title = text("point i"),
para = "abcdefghijakaka",
action = "asfasfasf"
para = "abcdefghijakddaka",
para = "abcdefghadfijakaka",
action = "asfasfafesf"
]).
point(2, [
title = text("point v"),
para = "abcdefghijdaaaakaka",
para = "abcdefghadfijakaka",
action = "asfasfafesf"
]).
footer(6.00).eg
Date : 11/02/2004
Time : 4.00
Venue : Carpark
Present :
1) bish tan
2) sarene tan
3) carlo pun
...
1) point i
abcdefghijakaka
ACTION : asfasfasf
abcdefghijakddaka
abcdefghadfijakaka
ACTION : asfasfafesf
...
..
i know bout using explode. Just wondering if there are any other function that i can use in PHP to extract the information out other then explode ??
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
preg_match() and preg_match_all()... or a stack parser
just wondering whats wrong with my regular expression ??
coz my preg match doesnt seems to be working
point([title = text("point i"),para1 = "abcdefghijakaka",action1 = "asfasfasf"]).
point([title = text("point v"),para1 = "abcdefgddahijakaka",action1 = "asfasdffasf"]).
i wan the following line to be printed as
title = text("point i"),para1 = "abcdefghijakaka",action1 = "asfasfasf"
title = text("point v"),para1 = "abcdefgddahijakaka",action1 = "asfasdffasf"
i tried using
preg_match_all("point([(.*)]).",
$body,
$out, PREG_PATTERN_ORDER);
coz my preg match doesnt seems to be working
point([title = text("point i"),para1 = "abcdefghijakaka",action1 = "asfasfasf"]).
point([title = text("point v"),para1 = "abcdefgddahijakaka",action1 = "asfasdffasf"]).
i wan the following line to be printed as
title = text("point i"),para1 = "abcdefghijakaka",action1 = "asfasfasf"
title = text("point v"),para1 = "abcdefgddahijakaka",action1 = "asfasdffasf"
i tried using
preg_match_all("point([(.*)]).",
$body,
$out, PREG_PATTERN_ORDER);
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
preg_match_all('#point\(\[(.*?)\]\)\.#s',$body,$out);
print_r($out);foreach ( $out[1] as $valuex ) {
echo $valuex;
}
i tried using the following code to print out the following. But it doesnt seems to work.Anything wrong with the code ??
title = text("point i"),para1 = "abcdefghijakaka",action1 = "asfasfasf"
title = text("point v"),para1 = "abcdefgddahijakaka",action1 = "asfasdffasf"
echo $valuex;
}
i tried using the following code to print out the following. But it doesnt seems to work.Anything wrong with the code ??
title = text("point i"),para1 = "abcdefghijakaka",action1 = "asfasfasf"
title = text("point v"),para1 = "abcdefgddahijakaka",action1 = "asfasdffasf"
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
mistakenly posted to a new thread:
allow the commas to get through? the commas contained in the text found inside the point() is captured, I'm not sure what your problem is really.
winsonlee wrote:preg_match_all('#point\(\[(.*?)\]\)\.#s',$body,$out);
some how the regular expression above doesnt allow the coma to get through. any idea how i can solved this problem ??
allow the commas to get through? the commas contained in the text found inside the point() is captured, I'm not sure what your problem is really.