1

hello I have a string the shows a users height like this,

6' 3"

I wanting to spilt this string into two values FEET and INCHES so I am left with something similar too,

$feet = "6'";
$inches = "3"/"

I so far have tried to do the following, to no avail,

split("[']", $height)

Naftali
  • 144,921
  • 39
  • 244
  • 303
Udders
  • 6,914
  • 24
  • 102
  • 194

4 Answers4

3
$height = "6' 3\"";
list($feet, $inches) = explode(" ", $height);

Demo: http://codepad.org/9WbAl1dn

Naftali
  • 144,921
  • 39
  • 244
  • 303
0

Split ist the Javascript function for this. You are looking for explode().

$array = explode(" ", $height)

You can combine it with list() to split the array into varialbes:

list($feet, $inches) = explode(" ", $height)
PiTheNumber
  • 22,828
  • 17
  • 107
  • 180
0

You can use the PHP explode() function.

Abbas
  • 14,186
  • 6
  • 41
  • 72
0

To get only the numeric values of feet and inches:

$parts = explode("' ", trim($height, '"'));
$feet = $parts[0];
$inches = $parts[1];

Combined with Neal's answer:

$height = "6' 3\"";
list($feet, $inches) = explode("' ", trim($height, '"'));
Community
  • 1
  • 1
Sonny
  • 8,204
  • 7
  • 63
  • 134