Page 1 of 1

get the character before ":"

Posted: Fri Jul 06, 2007 5:15 am
by gpong
<?
$text="PV-3510 : 3.5”Hard Disk Media playerPV-2510 : 2.5”Hard Disk Media"
?>
i have this string and I want to get the character before ":". What should I do? thank you

Posted: Fri Jul 06, 2007 5:22 am
by Appleton
Within that variable you have two ":" occurances?

Do you just want 1 character before the ":" which would be " " or are you looking to pick out the model numbers?

PV-3510
PV-2510
etc

help

Posted: Fri Jul 06, 2007 5:28 am
by gpong
i want to pick out the model numbers. thank you

Posted: Fri Jul 06, 2007 6:25 am
by John Cartwright
explode() and trim() may be of use :wink:

Posted: Fri Jul 06, 2007 8:43 am
by aceconcepts

Code: Select all

//explode("string seperator", $stringVar)

$code = explode(":", $text);
$model_number = $code[0];

Posted: Fri Jul 06, 2007 9:16 am
by MrPotatoes
the character or string before the semi colon?

use explode and trim like they said to get a clean array of information that you need.

from this string that you have: PV-3510 : 3.5”Hard Disk Media playerPV-2510 : 2.5, you'll end up with a 3 element single array. the first part of the array (index 0) will be the model number. the second and third will be the name and whatever that 2.5 is. from there if you want just a char then you'll have to use substr to get just a single alpha numberic byte.

enjoy

thank you its worked

Posted: Sun Jul 08, 2007 10:29 am
by gpong
i get it. thank you very much bro