我想从字符串MHadi
中提取Corp\MHadi
。
我使用以下代码,但每次都会出错。
$MyUser = "Corp\Mhadi";
$MyName = explode("\", $MyUser);
echo "Actual User = $MyUser <br />";
echo "First part = $MyName [0]<br />";
echo "Second part = $MyName [1]<br />";
答案 0 :(得分:0)
“\”逃脱一个角色。只是做
$MyName = explode("\\",$MyUser);
它应该有用
$MyUser = "Corp\Mhadi";
$MyName = explode("\\", $MyUser);
echo "Actual User = ".$MyUser." <br />";
echo "First part = ".$MyName[0]."<br />";
echo "Second part = ".$MyName[1]."<br />";
答案 1 :(得分:0)
你必须转义\
,因为这是php中的转义字符。
$MyUser = "Corp\Mhadi";
echo "Actual User = $MyUser <br />";
$MyName = explode('\\', $MyUser);
echo "First part = $MyName[0]<br />";
echo "Second part = $MyName[1]<br />";
这样就行了。