0

A php variable contains

$string = "256 Engineering Maths-I 21 -1 21 F";

printing

$string

gives output

256 Engineering Maths-I 21 -1 21 F

this variable should split in to

$n[0] = "256";
$n[1] = "Engineering Maths-I";
$n[2] = "21";
$n[3] = "-1";
$n[4] = "21";
$n[5] = "F";

I have tried with

$n = explode(" ", $string);

but it is splitting in to 2 parts

Please help me

ManojGeek
  • 1,977
  • 2
  • 16
  • 23

2 Answers2

3

What you are probably looking at is a tab separated string

Do this

$n = explode("\t", $string);

UPDATE The answer was that the text was delimited by a newline. so

$n = explode("\n", $string); 

The browser's behavior of collapsing whitespace to a single space was masking what was really happening.

Orangepill
  • 24,500
  • 3
  • 42
  • 63
  • THankyou so much for ur hint sir, actually it is \n nd I will accept ur answer in 9 mins, please edit ur answer – ManojGeek Jul 19 '13 at 21:43
1

You can also try to split on whitespace:

$n = preg_split('/\s+/', $string);
jh314
  • 27,144
  • 16
  • 62
  • 82