2

I am trying to find special character $@ from my string and trying to store all value after these special in a variable but I could not do this task. How do I find this $@ special character in my whole string and store all value after this special charecter in a variable. My string is:

 92~SAPL/1200/2012~2~LAXMAN SINGH AND OTHERS~SHANKER SINGH AND OTHERS~D~
 2014-04-10~09:31:13
 07/04/2014|93~SAPL/275/1998~1~RAM SWAROOP AND OTHERS~BABU RAM AND OTHERS~D~
 2014-04-10~09:31:13 07/04/2014|94~FAFOD/52/2013~3~RAM KUMAR PANDEY~RAJENDRA PANDEY AND
 ANOTHER~D~2014-04-10~09:31:13 07/04/2014$@2014-04-10~2014-04-09 
Giacomo1968
  • 25,759
  • 11
  • 71
  • 103

1 Answers1

-2

try this:

$string = "Your Entire String";
$explodedString = explode('$@', $string);

if(count($explodedString) > 1) {
   unset($explodedString[0]);
   $returnString = count($explodedString) > 1 ? $explodedString : $explodedString[0];
} else {
   $returnString = null;
}

if(is_array($returnString)) {
   //if you want to divide the string only to the first occurrence of $@ leave the below line as is else comment it out
   $returnString = implode('', $returnString);
}

echo $returnString;
Guns
  • 2,678
  • 2
  • 23
  • 51
  • 1
    Why do this when a simple `substr` will do? – Giacomo1968 Apr 09 '14 at 11:19
  • @JakeGould, a substr will surely do that, however, if the user wants to have it exploded and have it in an array why not use this small function to do that. The guy who asked this question is new to the forum. Such scripts might help him overcoming problems anywhere in the code. Hope you understand – Guns Apr 09 '14 at 11:21