I have something that shows up as $180 - ON HOLD That is made into a variable from a database field. How can I remove the "ON HOLD" part and have the variable remain as $180? I guess I would use explode?
first of all, there's about a million different ways to do this, here's one:
$t = '$180 - ON HOLD'; $t = trim($t); echo substr($t, 0, strpos($t, ' '));
whats another way?
You're not going to make me go through all 1 million, are you?
$t = '$180 - ON HOLD'; preg_match('/(\$[0-9]+)/', $t, $r); echo $r[1];
And another:
$t = '$180 - ON HOLD'; $t = str_replace(' - ON HOLD', '', $t); echo $t;
And another, although this way is kinda wasteful. Doing some time trials might be kinda intersting.
$t = '$180 - ON HOLD'; list($t) = explode(' ', $t); echo $t;