Forum Moderators: coopster

Message Too Old, No Replies

Small description link to big

         

patrixs

2:13 am on Jul 24, 2003 (gmt 0)

10+ Year Member



Hey,
This is just a small problem but I'm can't find a good solution to it... Anyone know the code to do the following?

"Cut" a big description and put ... at then end and a link that says "More info" that goes on the full description... I'm getting my description from a database... I'm just looking for the part that "cuts" the description...

Example :
Blah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah ¦¦¦ CUT ¦¦¦ (add "... More info", when you click you get the rest of the description->) blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahvvvBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blah

jatar_k

6:37 am on Jul 24, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



this will return the first 50 chars

$shorty = substr [ca2.php.net](string,0,50);
$shorty .= ".... <a href=\"somelink.html\">More info</a>";

vincevincevince

8:21 am on Jul 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



personally i'd try changing that to:

$shorty = preg_replace("/[^\.:!\?\)]*$/","",substr(string,0,100));
$shorty .= ".... <a href=\"somelink.html\">More info</a>";

That way it will trim at the end of the sentance before the 100 char mark. If you just want it not to cut the middle of a word, use:

$shorty = preg_replace("/[^ ]*$/","",substr(string,0,100));
$shorty .= ".... <a href=\"somelink.html\">More info</a>";

patrixs

2:35 pm on Jul 24, 2003 (gmt 0)

10+ Year Member



Exactly what I was looking for! Thx a buch!