Forum Moderators: coopster

Message Too Old, No Replies

php split between

         

ahmed24

10:11 am on Jul 15, 2009 (gmt 0)

10+ Year Member



i have the following code

$split = split('[<>']', $value);

that gets the data in between the < > characters in $value, but i would like to know how i can get the data from instead of < > i want it to be like START_ and _END. if i do it like:

$split = split('[START__END>']', $value);

it doesnt seem to work

any ideas?

thanks

ahmed24

10:42 am on Jul 15, 2009 (gmt 0)

10+ Year Member



instead of using a 1 character on each side as the identifier i am basically trying to use words.

can anyone help?

omoutop

10:48 am on Jul 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



preg_split() perhaps?

ahmed24

10:55 am on Jul 15, 2009 (gmt 0)

10+ Year Member



cant seem to get it to work even with preg_split()

any other ideas?

omoutop

12:11 pm on Jul 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



str_replace? explode?
cant think of anthing else

andrewsmd

1:36 pm on Jul 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



can you post an real example with a sample string and tell us what results you would expect? To me it looks like you have a typo right here
END>']'

Do you want END>]' or END>\'}]'

andrewsmd

1:51 pm on Jul 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I had to assume what your string looks like. Give me some more data and I can tweak this.

$str = "[<text in between 1>]we don't want this[<text in between 2>]we don't want this[<text in between 3>]";

$arr = explode("[<", $str);
$return = array();

foreach($arr as $i){

$tempStr = substr($i, 0, (strpos($i, ">]")));
array_push($return, $tempStr);

}//foreach