top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Finding the Middle elements of a String in PHP

+1 vote
511 views

Let's say the string is "ram,shyam,seeta,geeta" (not an array just a text string)

I see that I can use these (strpos)

$findme = ',';
$pos = strpos($this1, $findme);
$pos2 = strripos($this1, $findme);

$showfirst = substr($this1, 0, $pos); 
$showlast = substr($this1, $pos2+1, 9999 ); 
posted May 11, 2014 by Rameshwar

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+2 votes

Not sure what you are trying to do? If you're looking to get the words out of the string, just explode it into an array and get the elements you want from the array.

$str = ""ram,shyam,seeta,geeta";
$ary = explode(',',$str);
answer May 11, 2014 by Arjuna
0 votes

$str = ""ram,shyam,seeta,geeta";
$ary = explode(',',$str);

answer May 18, 2014 by Vrije Mani Upadhyay
...