remove array text from print_r and add some html...

Posted on 2011-10-04
Last Modified: 2012-05-12

I have a text field in my database, it i used for meta tags, the user enters them into the system as so...
learning,  training, accessibility

so i want to extract the items between the commas and display as text AND wrap some HTML around it...

I have no idea how to do this and spent the last hour reading with no luck.. this is my code so far

So far I have come up with this...

$str = $row_Recordset_getevent['blog_meta_tags'];

print_r(explode(',', $str, -1));

which will output...

Array ( [0] => learning [1] => training [2] => accessibility ) 

What I want it to output is...

<a href="blog_feed.php?tag=learning">learning</a>, <a href="blog_feed.php?tag=training">training</a>,<a href="blog_feed.php?tag=accessibility">accessibility</a>

And even better, if I could get inside the out put and add some PHP functions, that would be great...

Open in new window

Question by:jblayney
    LVL 13

    Accepted Solution

    the simple way of doing this would be to do this
    $tags=explode(',', $str, -1);
    $output = array();
    foreach($tags as $tag)
    $link = "a href='blog_feed.php?tag=$tag'>$tag</a>";
    $output[] = $link;
    $newstr = implode(",", $output); 

    Open in new window

    LVL 13

    Expert Comment

    woops on line 5 it should be $link = "<a href='blog_feed.php?tag=$tag'>$tag</a>";
    LVL 1

    Author Closing Comment

    thank you

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now