Posted By

nicolaspar on 07/12/06


Tagged


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

luman
meth
alexsancho


Php cortar string respetando palabras beta 0.2


 / Published in: PHP
 

echo cortarAdelante("hola mundo", 3, 1, 1 ); #Return hola

  1. function cortarAdelante( $cadena, $cuantos, $ponerPuntos=0, $sacarTags=0, $puntos1 = '...' ){
  2. $puntos = '';
  3. if( $ponerPuntos == 1 ){
  4. if( strlen( $cadena ) >= $cuantos) {
  5. $puntos = $puntos1;
  6. }
  7. }
  8. if( $sacarTags==1 ){
  9. $cadeba = sacarTags( $cadena );
  10. }
  11. $cadena .= ' ';
  12. $cadena = substr( $cadena, 0, $cuantos + 1 );
  13. $cadena = substr( $cadena, 0, strrpos( $cadena,' ') );
  14. return $cadena.$puntos;
  15. }
  16.  
  17. #funciones adicionales que usara
  18. function sacarTags( $str ){
  19. if( trim( $str )!='' ){
  20. $str = ereg_replace( "<([^>]+)>", "", $str );
  21. return $str;
  22. }else{
  23. return $str;
  24. }
  25. }
  26.  
  27. function sacarHref( $str ){
  28. if( trim( $str ) != '' ){
  29. $str = eregi_replace( "<a([^>]+)>|</a>", "", $str );
  30. return $str;
  31. }else{
  32. return $str;
  33. }
  34. }

Report this snippet  

You need to login to post a comment.