iZerang

Remove chars but stay first

Jun 1st, 2017
24,047
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.37 KB | None | 0 0
  1. <?php
  2. $string = 'Hello - Im - iZerang - the best - one!'; // phrase
  3.  
  4. function stripChars($a, $b = '', $c = 0) {
  5.     $get = explode("-", $a);
  6.     if(empty($get))
  7.         return $a;
  8.     foreach($get as $word) {
  9.         ++$c;
  10.         $b .= $word;
  11.         if($c == 1)
  12.             $b .= ' - ';
  13.     }
  14.     return $b;
  15. }
  16.  
  17. echo stripChars($string); // call function
  18. // result: Hello - Im iZerang the best one!
  19. ?>
Advertisement
Add Comment
Please, Sign In to add comment