<?
$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
get the character before ":"
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Code: Select all
//explode("string seperator", $stringVar)
$code = explode(":", $text);
$model_number = $code[0];- MrPotatoes
- Forum Regular
- Posts: 617
- Joined: Wed May 24, 2006 6:42 am
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
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
i get it. thank you very much bro