Php 如何在字符串中找到一个特殊字符,并将该字符后面的所有值存储在变量中
我正在尝试从字符串中查找特殊字符$@并尝试将这些特殊字符后面的所有值存储在变量中,但我无法执行此任务。如何在整个字符串中找到此$@特殊字符,并将此特殊字符后的所有值存储在变量中。我的字符串是:Php 如何在字符串中找到一个特殊字符,并将该字符后面的所有值存储在变量中,php,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
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
试试这个:
$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;
试试这个:
$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;
echo substr$string,strps$string,'$@'+1;echo substr$string,strps$string,'$@'+1;为什么一个简单的substr就可以这样做呢?@JakeGould,substr肯定可以这样做,但是,如果用户想将它分解并放入数组中,为什么不使用这个小函数来实现呢。问这个问题的人是论坛的新成员。这样的脚本可以帮助他克服代码中任何地方的问题。希望你能理解为什么一个简单的substr就可以做到这一点?@JakeGould,substr肯定可以做到这一点,但是,如果用户想将其分解并放入数组中,为什么不使用这个小函数来做到这一点呢。问这个问题的人是论坛的新成员。这样的脚本可以帮助他克服代码中任何地方的问题。希望你能理解