Combining lines

Discussion in 'PHP' started by hotfaps, Apr 8, 2010.

  1. #1
    echo '<a href="';
    echo $row['link'];
    echo '" target="_blank">';
    echo $row['capTitle'];
    echo '</a>';


    How can I make this link into one line of code, I have a hard time believing this is the most effective.
     
    hotfaps, Apr 8, 2010 IP
  2. skywebsol

    skywebsol Well-Known Member

    Messages:
    161
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #2
    echo '<a href="'.$row[link].'" target="_blank">'.$row[capTitle].'</a>';
     
    skywebsol, Apr 8, 2010 IP
  3. hotfaps

    hotfaps Active Member

    Messages:
    94
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    61
    #3
    So in php . combines something onto the end and lets you keep adding? Or just in the echo tag?
     
    hotfaps, Apr 8, 2010 IP
  4. skywebsol

    skywebsol Well-Known Member

    Messages:
    161
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #4
    yes keep adding to the string
     
    skywebsol, Apr 8, 2010 IP
  5. hotfaps

    hotfaps Active Member

    Messages:
    94
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    61
    #5
    Thanks alot, there is alot of places I can use that :) learn a little bit everyday!
     
    hotfaps, Apr 8, 2010 IP
  6. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #6
    echo '<a href="', $row['link'], '" target="_blank">', $row['capTitle'], '</a>';
    PHP:
    I've read somewhere, maybe in a blog post about PHP code optimization that the "," is faster than "." for string concatenation
     
    nabil_kadimi, Apr 9, 2010 IP
  7. ceo.ahlul

    ceo.ahlul Peon

    Messages:
    57
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    of if you want to combine some string in different line you can use like this:
    
    $var .= "Line1";
    $var .= "Line2";
    $var .= "Line3";
    
    PHP:
    This method will useful if you need add some process between the lines.
     
    ceo.ahlul, Apr 11, 2010 IP