PHP Snippet on a web page
| From: | Bluejays PC Services | Date: | Sat, 11 Mar 2006 15:59:20 +0000 |
| Subject: | PHP Snippet on a web page | ||
| Groups: | php.install | ||
| Request: | Send a blank email to php-install+get-17163@lists.php.net to get a copy of this message | ||
I am not sure whether this is the right place to ask this but I have been having great hassle trying to get this to work
This script gets a snippet from a paragraph in a mysql database and displays it on a web page......I want it to display the first 10 words in a paragraph but what ever I have tried it will only give me one word.... in the case of the version of the script below, just the first word.
The *"1/10" *in this line should be what determines how many words will be displayed...
*
*stripslashes(nl2br(cut_string($row["comment"],*"1/10"*,"<a href=\"full_summ.php?id=$row[id]\">
===============================
<?php
function cut_string($string,$wordnum,$trail)
{
$string_arr=explode(" ",$string);
for($i=0;$i<$wordnum;$i++)
{
$re_string=" ".$string_arr[$i];
}
$str=$re_string.$trail;
print $str;} //connect, select db, create query, run query, close connection $conn=mysql_connect("localhost", "user", "password") or die(mysql_error()); $database=mysql_select_db("fback", $conn)or die(mysql_error());
$sql="SELECT * FROM customer_feedback ORDER by id DESC LIMIT 25"; $result=mysql_query($sql);//PHP goes into while loop to return summaries of comments while($row=mysql_fetch_array($result)){ echo"<TR><td><B>Date: " ..strftime('%d/%m/%y',strtotime($row["date"]))."</B></td><td><B>Comment By:</B> ".Stripslashes($row["name"])."<td></tr>"; echo"<TR><TD COLSPAN=\"2\" valign\"top\"><B>Comment: </B>"; stripslashes(nl2br(cut_string($row["comment"],"1/10","<a href=\"full_summ.php?id=$row[id]\"> Read More>>></a>"))); echo"</td></tr>"; } //close database mysql_close($conn); ?> Any Ideas? Thanks! Jeremy -- Jeremy Oliver Bluejays PC Repair tel 020 8656 1056 mob 07855833401 www.bluejayspc.co.uk