PHP Texblock auf X Zeichen verkürzt darstellen und mit .. ersetzen

michi0815

michi0815

Mitglied
Thread Starter
Dabei seit
22.11.2011
Beiträge
46
Reaktionspunkte
3
Hallo MacUser Community,
vorab ich bin "just do it - Learning by doing" webprogrammierer und noch ein absoluter neuling in sachen php.

ich habe ein webseite mit dynamischen inhalts sprich die seite zeigt mir den gewünschten inhalt aus einer mysql db per php an was bestens funktioniert.
nun habe ich eine frontend seite für den kunden und ne backend seite wo die inhalte erstellt/bearbeitet/gelöscht werden sollen. da habe ich eine tabelle mit allen beiträgen (records) der DB.
nun möchte ich dass im textblock, da dort meist sehr viel drinsteht, nur ein teil des textes bzw des inhalts angezeigt wird und bsp nach 150 zeichen mit ... ergänzt wird.

kann mir jemand sagen was ich da in meinem code ergänzen muss damit dies funktioniert (code folgt noch) ?

bsp:
-Inhalt auf der frontendseite: bla bla bla langer text und so weiter-
-inhalt im backend: bla bla bl...
-->kürzung ab 10 zeichen

der code meiner backendseite(ps ich habe den php teil mit dreamweaver erstellt über die funktion "dynamic data" und recordset/server behaviours":

Code:
<?php require_once('../Connections/YMDataConnection.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_AdminRecordset = 10;
$pageNum_AdminRecordset = 0;
if (isset($_GET['pageNum_AdminRecordset'])) {
  $pageNum_AdminRecordset = $_GET['pageNum_AdminRecordset'];
}
$startRow_AdminRecordset = $pageNum_AdminRecordset * $maxRows_AdminRecordset;

mysql_select_db($database_YMDataConnection, $YMDataConnection);
$query_AdminRecordset = "SELECT * FROM news ORDER BY news.ID DESC";
$query_limit_AdminRecordset = sprintf("%s LIMIT %d, %d", $query_AdminRecordset, $startRow_AdminRecordset, $maxRows_AdminRecordset);
$AdminRecordset = mysql_query($query_limit_AdminRecordset, $YMDataConnection) or die(mysql_error());
$row_AdminRecordset = mysql_fetch_assoc($AdminRecordset);

if (isset($_GET['totalRows_AdminRecordset'])) {
  $totalRows_AdminRecordset = $_GET['totalRows_AdminRecordset'];
} else {
  $all_AdminRecordset = mysql_query($query_AdminRecordset);
  $totalRows_AdminRecordset = mysql_num_rows($all_AdminRecordset);
}
$totalPages_AdminRecordset = ceil($totalRows_AdminRecordset/$maxRows_AdminRecordset)-1;

$queryString_AdminRecordset = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_AdminRecordset") == false && 
        stristr($param, "totalRows_AdminRecordset") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_AdminRecordset = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_AdminRecordset = sprintf("&totalRows_AdminRecordset=%d%s", $totalRows_AdminRecordset, $queryString_AdminRecordset);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta name="robots" content="noindex, nofollow" />
	<meta name="author" content="Michael Ihde | Mimusto Multimedia" />
	<link href="../css/admin.css" rel="stylesheet" type="text/css" />
	<title>Yellowmusic | Admin</title>
</head>

<body>
<div id="frame1">
	<div id="frame2">
		<div id="mainframe">
			<div id="header">
				<a href="http://www.yellowmusic.ch/admin"><img id="header_img" src="../images/admin_header_img.gif" /></a>
			</div>
			<div id="navbar">
				<ul>
					<li><div id="activitem" class="activeitem"><a href="index.php">HOME</a></div></li>
					<li><div id="item" class="item"><a href="newpost_news.php">NEUER EINTRAG</a></div></li>
				</ul>
			</div>
			<div id="mainbox">
				<p class="title_01">News | Eintr&auml;ge</p>
				<p class="text_01" id="link">
					Hier sehen Sie alle Eintr&auml;ge der Seite&nbsp;<a href="http://www.yellowmusic.ch/" target="_blank">News</a>&nbsp;Ihrer Webseite.
					<br />
					<a href="newpost_news.php">&rArr;&nbsp;Neuer Eintrag erstellen</a>
					<br />
					<a href="http://www.yellowmusic.ch/" target="_blank">&rArr;&nbsp;Vorschau</a>
				</p>
				<table border="1">
					<tr>
						<td class="title_02">Titel</td>
						<td class="title_02">Inhalt</td>
						<td class="title_02">Datum</td>
						<td class="title_02" colspan="3">Funktion</td>
					</tr>
					<?php do { ?>
						<tr>
							<td class="text_01"><?php echo $row_AdminRecordset['title']; ?></td>
							<td class="text_01"><?php echo $row_AdminRecordset['content']; ?></td>
							<td class="text_01"><?php echo $row_AdminRecordset['date']; ?></td>
							<td class="text_01"><a href="detail.php?recordID=<?php echo $row_AdminRecordset['ID']; ?>"><img src="../images/select_icon.jpg" width="20" height="20" border="0" /></a></td>
							<td class="text_01"><a href="editpost.php?recordID=<?php echo $row_AdminRecordset['ID']; ?>"><img src="../images/edit_icon.jpg" width="20" height="20" border="0" /></a></td>
							<td class="text_01"><a href="deletepost.php?recordID=<?php echo $row_AdminRecordset['ID']; ?>"><img src="../images/delete_icon.jpg" width="20" height="20" border="0" /></a></td>
						</tr>
						<?php } while ($row_AdminRecordset = mysql_fetch_assoc($AdminRecordset)); ?>
				</table>
				<table border="0">
					<tr>
						<td>
							<?php if ($pageNum_AdminRecordset > 0) { // Show if not first page ?>
								<a href="<?php printf("%s?pageNum_AdminRecordset=%d%s", $currentPage, 0, $queryString_AdminRecordset); ?>"><img src="../images/First.gif" /></a>
							<?php } // Show if not first page ?>
						</td>
						<td>
							<?php if ($pageNum_AdminRecordset > 0) { // Show if not first page ?>
								<a href="<?php printf("%s?pageNum_AdminRecordset=%d%s", $currentPage, max(0, $pageNum_AdminRecordset - 1), $queryString_AdminRecordset); ?>"><img src="../images/Previous.gif" /></a>
							<?php } // Show if not first page ?>
						</td>
						<td>
							<?php if ($pageNum_AdminRecordset < $totalPages_AdminRecordset) { // Show if not last page ?>
								<a href="<?php printf("%s?pageNum_AdminRecordset=%d%s", $currentPage, min($totalPages_AdminRecordset, $pageNum_AdminRecordset + 1), $queryString_AdminRecordset); ?>"><img src="../images/Next.gif" /></a>
							<?php } // Show if not last page ?>
						</td>
						<td>
							<?php if ($pageNum_AdminRecordset < $totalPages_AdminRecordset) { // Show if not last page ?>
								<a href="<?php printf("%s?pageNum_AdminRecordset=%d%s", $currentPage, $totalPages_AdminRecordset, $queryString_AdminRecordset); ?>"><img src="../images/Last.gif" /></a>
							<?php } // Show if not last page ?>
						</td>
						<td class="text_01">
							Eintrag <?php echo ($startRow_AdminRecordset + 1) ?> bis <?php echo min($startRow_AdminRecordset + $maxRows_AdminRecordset, $totalRows_AdminRecordset) ?> von <?php echo $totalRows_AdminRecordset ?>
						</td>
					</tr>
				</table>
			</div>
		</div>
	</div>
</div>

</body>
</html>
<?php
mysql_free_result($AdminRecordset);
?>

vielen dank im voraus!
 
Code:
$textblock = (strlen($textblock) > 150) ? substr($textblock, 0, 150) . '...' : $textblock;
 
danke für die antwort aber habs nach stundenlangem googeln und ausprobieren selbst rausgefunden. :)

für die dies interessiert:
Code:
<?php echo $row_AdminRecordset['content'] = substr($row_AdminRecordset['content'], 0, 80 ); ?>

LG Michi
 
Zurück
Oben Unten