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

Posted on 2011-10-04
Medium Priority
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  php.net 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
  • 2
LVL 13

Accepted Solution

haloexpertsexchange earned 2000 total points
ID: 36911501
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

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

Author Closing Comment

ID: 36911858
thank you

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month13 days, 22 hours left to enroll

807 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