$data['subject']= "Languages > English";
//This is how I get the string before the symbol '>'.
$subject = substr($data['subject'], 0, strpos($data['subject'], "> "));
但现在我需要在'>'之后得到消息。符号。如何更改上面的代码?
答案 0 :(得分:4)
http://php.net/manual/fr/function.substr.php
$subject = substr($data['subject'], strpos($data['subject'], "> "));
但你应该看看爆炸:http://php.net/manual/fr/function.explode.php
$levels = explode(" > ", $data['subject']);
$subject = $levels[0];
$language = $levels[1];
答案 1 :(得分:4)
或使用爆炸:
$array = explode(' > ', $data['subject']);
echo $array[0]; // Languages
echo $array[1]; // English
答案 2 :(得分:1)
如果您想要>之前和之后的数据,我会使用爆炸。
$data['subject'] = "Languages > English";
$data['subject'] = array_map('trim', explode('>', $data['subject'])); // Explode data and trim all spaces
echo $data['subject'][0].'<br />'; // Result: Languages
echo $data['subject'][1]; // Result: English
答案 3 :(得分:0)
你可以这样做,
然后保留数组的最后一个值
<?php
$data['subject']= "Languages > English";
$subject = end(explode('>',$data['subject']));