Page 1 of 1

Identify how many coma are there

Posted: Wed Aug 10, 2005 8:40 am
by winsonlee
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.

Posted: Wed Aug 10, 2005 8:51 am
by shiznatix
well with that string you could do

Code: Select all

$first = explode('*', $string);
$second = explode('^', $first[1]);
$arr[] = $first[0];
$arr[] = $second[0];
$arr[] = $second[1];

print_r($arr);
but if its just commas that would be a whole lot easier

Posted: Wed Aug 10, 2005 9:09 am
by thegreatone2176
yea if it was all commas you could just explode on , and then count()

Posted: Mon Aug 22, 2005 10:00 am
by winsonlee

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).
all the following information will be stored in a text file. what i wanted is to extract the information out from the text file and display in a normal viewable html format.

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 ??

Posted: Mon Aug 22, 2005 10:06 am
by feyd
preg_match() and preg_match_all()... or a stack parser

Posted: Mon Aug 22, 2005 6:30 pm
by winsonlee
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);

Posted: Mon Aug 22, 2005 6:38 pm
by feyd

Code: Select all

preg_match_all('#point\(\[(.*?)\]\)\.#s',$body,$out);
print_r($out);

Posted: Mon Aug 22, 2005 6:50 pm
by winsonlee
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"

Posted: Mon Aug 22, 2005 7:02 pm
by winsonlee
sorry .. it works . i got it mixed up

Posted: Mon Aug 22, 2005 7:44 pm
by feyd
mistakenly posted to a new thread:
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.