Hi
I am working on a new project, I have not been working with PHP for very long, and basically what is happening is this.
A server is sending strings to my server on a specific port. I am using fsockopen to listen on that port.
What I am struggling with is that they send information to me like this
NMmike|SNjones|BD19820115|CNfrance|LNenglish
I am using
$inputArray = explode("|",$input);
to store each string in a variable using "|" as the delimeter, which works well. The string all have different prefixes which describe the rest of the string, like NM is Name so they send NMmike, telling me the Name is mike. Does anyone know an efficient method to perhaps read the first two characters of a string and then remove them without knowing the actual length of the string?
Any help would be great
Getting values from post
Moderator: General Moderators
Re: Getting values from post
For example:
Code: Select all
$input = 'NMmike|SNjones|BD19820115|CNfrance|LNenglish';
$inputArray = explode("|", $input);
$resultArray = array();
foreach ($inputArray as $ia) {
$prefix = substr($ia, 0, 2);
$resultArray[$prefix] = substr($ia, 2);
}
print_r($resultArray);-
blingblouw
- Forum Newbie
- Posts: 2
- Joined: Fri Nov 26, 2010 1:56 am
Re: Getting values from post
Thanks man,
I am already doing that to add them into an array, what I need to do is get those two character prefixes and then strip them from the rest of the string
so my variable NMmike
I get the two leading chars NM so I know what ever follows is the name, I then strip that from the variable and add only the name "mike" to the DB.
Can that be done?
edit:
Not to worry, I have found a solution. All I did was
$realstring = substr($value,2);
$prefix = substr($value,0,2);
I am already doing that to add them into an array, what I need to do is get those two character prefixes and then strip them from the rest of the string
so my variable NMmike
I get the two leading chars NM so I know what ever follows is the name, I then strip that from the variable and add only the name "mike" to the DB.
Can that be done?
edit:
Not to worry, I have found a solution. All I did was
$realstring = substr($value,2);
$prefix = substr($value,0,2);