Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A bit of Syntax help 1

Status
Not open for further replies.

purcion

Programmer
Feb 14, 2005
32
AU
Hi
I am using a function
==============================================
<?php
function nicetrim ($s) {

$MAX_LENGTH = 250;
$Str = html_entity_decode($s);
if (strlen($Str) <= $MAX_LENGTH) {
return $s;
}

$s2 = substr($Str, 0, $MAX_LENGTH - 3);
$s2 .= "...More";
return htmlentities($s2);
}
?>
=================================================

what it does is basically trims all but 250 characters
from a string varible and adds ...More to the end of it ,so in my html its called like this

<td><div align="left">'.nicetrim ($description).'</div></td>


Im having a problem because I need to make the
$s2 .= "...More"; part of the function a different colored font from the rest of the $description and have an <a href around it so that when the user clicks on ...More they are linked to another page. It should be pretty trivial but all that ive tried Im not getting the desired outcome would some one please show me the way .
Thanks again
 
I would change the function to be:

Code:
function nicetrim ($s, $color="black", $href="") {

...

  $s .= "<a href='$href'><font color='$color'>... More</font></a>";

  return $s;
}

Would that work?
 
thanks, no i cant get what your suggesting to work could you be more specific like actually change the function I listed
I would really appreciate that in the function i listed
$s2 .=
is returning the "..more" string
you have got $s .= returning it

Im just abit confused with how to fill in the blanks

Thanks again
==============================================
<?php
function nicetrim ($s) {

$MAX_LENGTH = 250;
$Str = html_entity_decode($s);
if (strlen($Str) <= $MAX_LENGTH) {
return $s;
}

$s2 = substr($Str, 0, $MAX_LENGTH - 3);
$s2 .= "...More";
return htmlentities($s2);
}
?>
=================================================
 
I guess that was just an a little overview from Eric. He wanted to say:
Code:
<?php  
function nicetrim ($s) {

  $MAX_LENGTH = 250;
  $Str = html_entity_decode($s);
  if (strlen($Str) <= $MAX_LENGTH) {
   return $s;
  }

  $s2 = substr($Str, 0, $MAX_LENGTH - 3);
  $s2 .= [b]'<a href="$page" style="color: red;">...More</a>'[/b];
  return htmlentities($s2);
}
?>
 
No i got what ericbrunsan meant and It just doesnt work .
what you guys have suggested is pretty much what i tried before i posted this question. when nicetrim($s) is called down in the html code it out puts everything as a string after $s2. everything including the new variables
$s2 .= '<a href="$page" style="color: red;">...More</a>';
wont output a hyperlink it will output the text as you see it no matter where or how you declare your $page variable.
it wont output it as a link. It will read it in as a string and not html ,Bummer I thought it was something simple, there must be a simple soloution to this well thanks for your help anyway
 
i've not been following this thread so apologies for sticking my nose in ... but shouldn't the last few lines be:
i.e. the last line is written in html already so encoding it again will bust the link.

Code:
  $s2 = substr($Str, 0, $MAX_LENGTH - 3);
  $s3 = '<a href="$page" style="color: red;">...More</a>';
  return htmlentities($s2).$s3;
 
Yes !!! good man
thank you jpadie that works perfectly, Im very happy
thanks to the others as well for having a go
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top