SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2010
    Posts
    167
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What is wrong with this echo?

    Hi all.

    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.

    PHP Code:
    $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:

    PHP Code:
    $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...

    PHP Code:
    $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:

    PHP Code:
    $msg = echo($truncated$url); 
    I have also tried all three of the above without the brackets.

    What should it be?

  2. #2
    SitePoint Wizard gold trophysilver trophybronze trophy dc dalton's Avatar
    Join Date
    Nov 2004
    Location
    Right behind you, watching, always watching.
    Posts
    5,431
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $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

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    either

    $msg =

    or

    echo

    but not both in the one statement unless you swap them around the other way

    echo $msg =
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,068
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $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.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by SpacePhoenix View Post
    PHP Code:
    $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.
    That doesn't change the fact that you cannot have $msg = echo which is what the code reads that isn't working.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •