views:

45

answers:

1

I need to figure out how to do some C# code in php, and im not sure exactly how.

so first off i need the Split function, im going to have a string like

"identifier 82asdjka271akshjd18ajjd" 

and i need to split the identifier word from the rest. so in C#, i used string.Split(new char{' '}); or something like that (working off the top of my head) and got two strings, the first word, and then the second part.. i understand that the php split function has been deprecated as of PHP 5.3.0.. so thats not an option, what are the alternatives?

and im also looking for a IndexOf function, so if i had the above code again as an example, i would need the location of 271 in the string, so i can generate a substring.

+5  A: 

you can use explode for splitting and strpos for finding the index of one string inside another.

$a = "identifier 82asdjka271akshjd18ajjd";
$arr = explode(' ',$a); // split on space..to get an array of size 2.
$pos = strpos($arr[1],'271'); // search for '271' in the 2nd ele of array.
echo $pos; // prints 8
codaddict
exactly what i was looking for. for some damn reason i couldnt find it on google. :/
Tommy