what is wrong with this php href tag

Discussion in 'PHP' started by inhook, Apr 23, 2008.

  1. #1
    I am new to php and cannot figure out what is wrong with this php tag, gives me a parser error, i know there is a quote that i have to add or escape a quote but i cannot get it where to do that


    <?php echo "<a href=\"index.php?pageid=".$page_id. "&pagename=".$page_name. title=\" .$page_name. "\" class=\"navText\">".$page_name."</a>";?>
    Code (markup):
    anyhelp will be appreciated.
     
    inhook, Apr 23, 2008 IP
  2. inhook

    inhook Well-Known Member

    Messages:
    248
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    108
    #2
    sorry some how i created multiple posts was not intending to do that. If moderators can close the other two that got created in error,
     
    inhook, Apr 23, 2008 IP
  3. Oli3L

    Oli3L Active Member

    Messages:
    207
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    70
    #3
    
    <?php echo "<a href=\"index.php?pageid=".$page_id."&pagename=".$page_name."\" title=\"".$page_name. "\" class=\"navText\">".$page_name."</a>";?>
    
    PHP:
    try this.
     
    Oli3L, Apr 23, 2008 IP
  4. inhook

    inhook Well-Known Member

    Messages:
    248
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    108
    #4
    worked like a charm thank you very much
     
    inhook, Apr 23, 2008 IP
  5. phpl33t

    phpl33t Banned

    Messages:
    456
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Instead of putting in all of those backslashes, use single quotes on the outside.

    
    <?php
    	echo '<a href="index.php?pageid='.$page_id.'&pagename='.$page_name.'" title="' .$page_name. '" class="navText">'.$page_name.'</a>';
    ?>
    
    PHP:
    See how much cleaner that looks?
     
    phpl33t, Apr 23, 2008 IP
  6. inhook

    inhook Well-Known Member

    Messages:
    248
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    108
    #6
    yes it does thanks
     
    inhook, Apr 24, 2008 IP
  7. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #7
    Almost as clean as using sprintf. :D

    <?php
    	echo sprintf('<a href="index.php?pageid=%1$s&pagename=%2$s" title="%2$s" class="navText">%2$s</a>', $page_id, $page_name);
    ?>
    PHP:
     
    joebert, Apr 24, 2008 IP
  8. inhook

    inhook Well-Known Member

    Messages:
    248
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    108
    #8
    hmm sprintf seems pretty clean too, can i add more parameters or variables and print them as %3$s etc
     
    inhook, Apr 30, 2008 IP
  9. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #9
    joebert, May 3, 2008 IP