Reputation: 2466
$data['subject']= "Languages > English";
//This is how I get the string before the symbol '>'.
$subject = substr($data['subject'], 0, strpos($data['subject'], "> "));
But Now I need to get word after the '>' symbol. How do I alter the code above?
Upvotes: 2
Views: 7196
Reputation: 2375
You can do this way,
$data['subject']= "Languages > English";
$subject = end(explode('>',$data['subject']));
Upvotes: 0
Reputation: 1175
$subject = substr($data['subject'], strpos($data['subject'], "> "));
But you should have a look at explode : https://php.net/explode
$levels = explode(" > ", $data['subject']);
$subject = $levels[0];
$language = $levels[1];
Upvotes: 4
Reputation: 61
If you want the data before and after the >, I would use an explode.
$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
Upvotes: 1
Reputation: 10714
Or using explode :
$array = explode(' > ', $data['subject']);
echo $array[0]; // Languages
echo $array[1]; // English
Upvotes: 4