cbresources — 2011-10-19T20:23:30-04:00 — #1
I'm trying to echo a variable followed by a link and Dreamweaver's code hinter keeps flagging it up as an error.
The variable is $truncated which takes a string and shortens it to 130 characters or less (without cutting in the middle of a word). This is the $truncated variable.
$truncated = substr($longstring,0,strpos($longstring,' ',130));
And now I want to create another variable that takes the shortened text and adds a "Read More" link afterwards...
I'm doing it like this:
$msg = echo($truncated "<a href='http://ivegotkids.com/aries'>Read More</a>");
Dreamweaver keeps on telling me that last line is incorrect.
I have also tried it with a comma after $truncated...
$msg = echo($truncated, "<a href='http://ivegotkids.com/aries'>Read More</a>");
I have also tried it by putting the link in a separate variable called $url and echoing both like this:
$msg = echo($truncated, $url);
I have also tried all three of the above without the brackets.
What should it be?
dc_dalton — 2011-10-19T20:29:00-04:00 — #2
$msg = echo $truncated . "<a href='http://ivegotkids.com/aries'>Read More</a>";
You forgot the concatenation operator between the variable and the string, also you don't need () around an echo
felgall — 2011-10-19T21:00:38-04:00 — #3
but not both in the one statement unless you swap them around the other way
echo $msg =
spacephoenix — 2011-10-20T02:11:06-04:00 — #4
$msg = " $truncated <a href='http://ivegotkids.com/aries'>Read More</a>";
The variable can go inside the " as any variable inside a set of " is parsed.
felgall — 2011-10-20T04:08:14-04:00 — #5
That doesn't change the fact that you cannot have $msg = echo which is what the code reads that isn't working.