Guest User

Untitled

a guest
Jun 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. $string = '23/CSE/4/2014';
  2. $array = explode('/', $string);
  3.  
  4. echo $array[0]; // 23
  5. echo $array[1]; // CSE
  6. echo $array[2]; // 4
  7. echo $array[3]; // 2014
  8.  
  9. $main_string = "23/CSE/4/2014";
  10. $sub_string = "/CSE/4/2014";
  11. echo str_replace($sub_string, '', $main_string);
  12. // 23
  13.  
  14. $main_string = "23/CSE/4/2014"; // or "CSE/4/2014/23"
  15. $sub_string = "CSE/4/2014"; // notice no leading/trailing slash on this value
  16. echo trim(str_replace($sub_string, '', $main_string), '/'); // leading/trailing slashes are trimmed
  17. // 23
Add Comment
Please, Sign In to add comment