Jump to content

Função alternativa ao str_split


AriOps

Recommended Posts

pois mas no explode tu tens de usar o caracter onde queres efectuar a divisão, e como neste caso eu preciso de separar todos os algarismos de um número...

Quabnto a criar uma função do género, vou ver disso... 😉

Cumps

Acho que não tem nenhuma função parecida com str_split()... talvez substr(); mas também está bocado longe de ser parecida

Link to comment
Share on other sites

Já arranjei a função:

<?php
if(!function_exists('str_split')){
   function str_split($string,$split_length=1){
       $count = strlen($string); 
       if($split_length < 1){
           return false; 
       } elseif($split_length > $count){
           return array($string);
       } else {
           $num = (int)ceil($count/$split_length); 
           $ret = array(); 
           for($i=0;$i<$num;$i++){ 
               $ret[] = substr($string,$i*$split_length,$split_length); 
           } 
           return $ret;
       }     
   } 
}
?>

Cumps 😉

Daniel Correia

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.