Advertisement
niammuddin

ambil huruf pertama PHP

Oct 23rd, 2017
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.24 KB | None | 0 0
  1. <?php
  2. function pertaman($kata) {
  3. $sim = '-';
  4. $str = explode(' ', $kata);
  5. $initials = $str[0];
  6. if ($initials[0] == $sim) {
  7. $hasil = $initials[1];
  8. }
  9. else{
  10. $hasil = $initials[0];
  11. }
  12. return $hasil;
  13. }
  14. echo pertaman('-dunia ini sangat indah');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement