2
$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?

112233
  • 2,406
  • 3
  • 38
  • 88
  • possible duplicate of [Get everything after a certain character](http://stackoverflow.com/questions/11405493/get-everything-after-a-certain-character) – George Aug 05 '15 at 08:56

4 Answers4

4

https://php.net/substr

$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];
Syscall
  • 19,327
  • 10
  • 37
  • 52
Ianis
  • 1,165
  • 6
  • 12
4

Or using explode :

$array = explode(' > ', $data['subject']);
echo $array[0]; // Languages
echo $array[1]; // English
Vincent Decaux
  • 9,857
  • 6
  • 56
  • 84
1

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
Narendrasingh Sisodia
  • 21,247
  • 6
  • 47
  • 54
0

You can do this way,

  1. your string is converted in an array
  2. then you keep the last value of your array
$data['subject']= "Languages > English";
$subject = end(explode('>',$data['subject']));
A.L
  • 10,259
  • 10
  • 67
  • 98
Sylvain Martin
  • 2,365
  • 3
  • 14
  • 29