如何在字符串中找到特殊字符并将此字符后的所有值存储在变量中

时间:2014-04-09 10:58:08

标签: php

我正在尝试从我的字符串中找到特殊字符$@,并尝试将这些特殊值后的所有值存储在变量中,但我无法执行此任务。如何在整个字符串中找到此$@特殊字符,并将所有值存储在变量中的此特殊字符之后。我的字符串是:

 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 

1 个答案:

答案 0 :(得分:-2)

试试这个:

$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;