Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: tag links

  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    77
    Thanks
    4
    Thanked 0 Times in 0 Posts

    tag links

    I have db with a column that contains word tags separated with ","
    I populate pages with data from db and when I echo the tags I wan't to echo as links that make a search for that word.
    how can I do that?
    thank you

  • #2
    Regular Coder
    Join Date
    May 2007
    Posts
    108
    Thanks
    19
    Thanked 13 Times in 13 Posts
    This will get you started. It assumes that the tags are separated by a comma with no space.

    Code:
    <?
    
    $tags = 'apple,banana,orange,kiwi'
    
    $tags = explode(',', $tags);
    
    foreach ($tags as $t) { ?><a href="?tag=<?=urlEncode($t)?>"><?=htmlSpecialChars($t)?></a><br /><? }
    
    ?>

  • #3
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by >ssp-cdr< View Post
    This will get you started. It assumes that the tags are separated by a comma with no space.

    PHP Code:
    <?

    $tags 
    'apple,banana,orange,kiwi'

    $tags explode(','$tags);

    foreach (
    $tags as $t) { ?><a href="?tag=<?=urlEncode($t)?>"><?=htmlSpecialChars($t)?></a><br /><? }

    ?>
    Spaces wouldn't be a problem. You could either array_map() tags with the trim() function, or trim $t every time round.
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.


  •  

    Posting Permissions

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