How to split a line and find the occurrence of one line in another?

I need to figure out how to make C # code in php, and I don’t know exactly how to do it.

so first I need a Split function, im will have a string like

"identifier 82asdjka271akshjd18ajjd" 

and I need to separate the identifier word from the rest. so in c # i used string.Split (new char {''}); or something like that (leaning back from my head) and got two lines, the first word, and then the second part. I understand that the php sharing function has been deprecated since PHP 5.3.0 .. so this is not an option, what are the alternatives?

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

+4
source share
1 answer

you can use explode to split and strpos to find the index of one row 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 
+6
source

All Articles