Forum Moderators: coopster
Assume I already have a db connection...so from inserting
into html template engine which gets crunched by php what would I do?
<?php #*$!x.... ?>
How about if you return the primary key of that row in the database along with a substring of the description. Lay down the description and then make the "More ..." a link to your next processing script with the primary key as the value to be used to retrieve the article again on your next display page.
char_count or something but if you could get write the simple script it should take or at least give me a better idea... the row its comming from is "car_description"
care to help?
and thanks for the welcome...
Yes, everyone here cares to help. Have you already written some code? or your techs have? i mean if it's only about taking description from the database field and then showing it in a short form, thats pretty easy, but i dunno whats the status of code with you. if you could post related portion of your existing work, this would be pretty easy for anyone to assist and get that to work as expected.
regards
Kami
String = "Our new project is beginning to take shape with an emphasis on tomorrow's economic climate as predicted by Professor Smith in yesterday's news."
Cut after so many characters, not words:
String = "Our new project is beginning to take shape with an emphasis on tomorrow's eco"
Now move back to the first space, in this case after the word "tomorrow's". Add ending to suit, like so:
String = "Our new project is beginning to take shape with an emphasis on tomorrow's... (More)"
That ought to do it.
$string = substr($string, 0, 50);
would cut it down to 50 characters. and then, if you don't want a word to be cut right in the middle, you can create a simple while loop that loops until you reach the first space. that would be like:
$char = strlen($string);
while ($char > 0)
{
if ($string{$char} == " ") break;
$char = $char - 1;
}
$string = substr($string, 0, $char);
and finally, add three dots to the end of the string.
echo $string."...";
hope it helps.
cheers,
taylan
<?php
$text = $row_recap['text'];
if (strlen($text) > 300) {
$ext = "... <a href='readmore.php'>read more</a>";
} else {
$ext = "";
}
function elliStr($s,$n) {
for ( $x = 0; $x < strlen($s); $x++ ) {
$o = ($n+$x >= strlen($s)? $s : ($s{$n+$x} == " "?
substr($s,0,$n+$x) . "..." : ""));
if ( $o!= "" ) { return $o; }
}
}
?>
<?php echo (elliStr("$text", 300)) . $ext;?>