Foros del Web » Programando para Internet » PHP »

acortar cadena php

Estas en el tema de acortar cadena php en el foro de PHP en Foros del Web. hola buenas tengo este script @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código PHP: Ver original <?php require_once ( 'Connections/hoysale.php' ) ; ?> <?php function GetSQLValueString ( $theValue , $theType ...
  #1 (permalink)  
Antiguo 31/08/2012, 17:33
 
Fecha de Ingreso: marzo-2011
Mensajes: 115
Antigüedad: 13 años, 1 mes
Puntos: 0
acortar cadena php

hola buenas tengo este script
Código PHP:
Ver original
  1. <?php require_once('Connections/hoysale.php'); ?>
  2. <?php
  3. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  4. {
  5.   $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
  6.  
  7.   switch ($theType) {
  8.     case "text":
  9.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  10.       break;    
  11.     case "long":
  12.     case "int":
  13.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  14.       break;
  15.     case "double":
  16.       $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  17.       break;
  18.     case "date":
  19.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  20.       break;
  21.     case "defined":
  22.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  23.       break;
  24.   }
  25.   return $theValue;
  26. }
  27.  
  28. $editFormAction = $_SERVER['PHP_SELF'];
  29. if (isset($_SERVER['QUERY_STRING'])) {
  30.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  31. }
  32.  
  33. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  34.   $insertSQL = sprintf("INSERT INTO comentarios (id_noticia, detalle) VALUES (%s, %s)",
  35.                        GetSQLValueString($_POST['id_noticia'], "int"),
  36.                        GetSQLValueString($_POST['detalle'], "text"));
  37.  
  38.   mysql_select_db($database_hoysale, $hoysale);
  39.   $Result1 = mysql_query($insertSQL, $hoysale) or die(mysql_error());
  40.  
  41.   $insertGoTo = "preguntar.php";
  42.   if (isset($_SERVER['QUERY_STRING'])) {
  43.     $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  44.     $insertGoTo .= $_SERVER['QUERY_STRING'];
  45.   }
  46.   header(sprintf("Location: %s", $insertGoTo));
  47. }
  48.  
  49. //NeXTenesio Special List Recordset
  50. $colname_noticias = "-1";
  51. if (isset($_GET['id'])) {
  52.   $colname_noticias = $_GET['id'];
  53. }
  54. mysql_select_db($database_hoysale, $hoysale);
  55.  
  56. $query_noticias = sprintf("SELECT * FROM noticias WHERE id = %s ORDER BY id DESC", $colname_noticias);
  57. $noticias = mysql_query($query_noticias, $hoysale) or die(mysql_error());
  58. $row_noticias = mysql_fetch_assoc($noticias);
  59. $totalRows_noticias = mysql_num_rows($noticias);
  60. //End NeXTenesio Special List Recordset
  61.  
  62. //NeXTenesio Special List Recordset
  63. $colname_comentar = "-1";
  64. if (isset($_GET['id'])) {
  65.   $colname_comentar = $_GET['id'];
  66. }
  67. mysql_select_db($database_hoysale, $hoysale);
  68.  
  69. $query_comentar = sprintf("SELECT * FROM comentarios WHERE id_comentario = %s ORDER BY id_comentario DESC", $colname_comentar);
  70. $comentar = mysql_query($query_comentar, $hoysale) or die(mysql_error());
  71. $row_comentar = mysql_fetch_assoc($comentar);
  72. $totalRows_comentar = mysql_num_rows($comentar);
  73. //End NeXTenesio Special List Recordset
  74.  
  75. mysql_free_result($noticias);
  76.  
  77. mysql_free_result($comentar);
  78. ?>
  79. <table width="500">
  80.   <tr>
  81.     <td><?php echo $row_noticias['id']; ?></td>
  82.     <td><a href="comentar.php?id=<?php echo $row_noticias['id']; ?>"><?php  echo $row_noticias['detalle']; ?></a></td>
  83.   </tr>
  84.   <tr>
  85.     <td>&nbsp;</td>
  86.     <td>&nbsp;</td>
  87.   </tr>
  88.   <tr>
  89.     <td>&nbsp;</td>
  90.     <td>&nbsp;
  91.       <form method="post" name="form1" action="<?php echo $editFormAction; ?>">
  92.         <table align="center">
  93.           <tr valign="baseline">
  94.             <td nowrap align="right" valign="top">Detalle:</td>
  95.             <td><textarea name="detalle" cols="50" rows="5"></textarea>
  96.             </td>
  97.           </tr>
  98.           <tr valign="baseline">
  99.             <td nowrap align="right">&nbsp;</td>
  100.             <td><input type="submit" value="Insertar registro"></td>
  101.           </tr>
  102.         </table>
  103.         <input type="hidden" name="id_noticia" value="<?php echo $row_noticias['id']; ?>">
  104.         <input type="hidden" name="MM_insert" value="form1">
  105.       </form>
  106.     <p>&nbsp;</p></td>
  107.   </tr>
  108.   <tr>
  109.     <td>&nbsp;</td>
  110.     <td>&nbsp;</td>
  111.   </tr>
  112. </table>

anda bien de bien. lo que quiero es es acortar la cadena
Código PHP:
Ver original
  1. <?php  echo $row_noticias['detalle']; ?>
que donde se muestra la noticia, o sea lo que quiero es que solo se muestre una parte de la misma y tenga un leer más..

gracias!!!
  #2 (permalink)  
Antiguo 31/08/2012, 18:02
 
Fecha de Ingreso: agosto-2011
Ubicación: Santo Domingo
Mensajes: 487
Antigüedad: 12 años, 8 meses
Puntos: 31
Respuesta: acortar cadena php

utiliza la function " substr "

Por ejemplo

<?php echo substr($row_noticias['detalle'], 0,50); ?>

con este ejemplo obtendria caractares del 0 al 50

Saludos
__________________
El talento se educa en la KARMA y el carácter en la tempestad.
Gabriel De Los Santos
  #3 (permalink)  
Antiguo 01/09/2012, 06:22
Avatar de antoniopol  
Fecha de Ingreso: agosto-2012
Ubicación: Valladolid
Mensajes: 114
Antigüedad: 11 años, 7 meses
Puntos: 21
Respuesta: acortar cadena php

Hola ofertasdiarias, yo creo que buscas esto

[URL="http://www.forosdelweb.com/f18/cortar-texto-por-palabras-215428/"]http://www.forosdelweb.com/f18/cortar-texto-por-palabras-215428/[/URL]

En este hilo muestran como acortar texto sin cortar una palabra, bastante interesante y seguro que es lo que buscas.
__________________
>> Blog de desarrollo web.
>> @antoniopol06 amante de la Web =D

Etiquetas: acortar, html, mysql, registro, sql, cadenas
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 09:14.