Jonathan Clark
Jonathan Clark

Reputation: 20538

Get tags from URL segment

I am developing an web app using Codeigniter. In this app I got a tag based search. I need people to be able to use an URL where the tags are predefined and then do a search using them.

Like this:

http://example.com/search/tags/tag1/tag2/tag3

How can I get all segments (tags) efter the tags segment?

Thankful for all input!

Upvotes: 1

Views: 178

Answers (3)

FrontEnd Expert
FrontEnd Expert

Reputation: 5803

Try this:-

         <script type="text/javascript">
        jQuery(document).ready(function(){

        var url = http://example.com/search/tags/tag1/tag2/tag3;

parts = url.split('/');
alert(parts[1]);
   ​});
</script>

You have to fetch array values according to u.

Upvotes: 1

Harry
Harry

Reputation: 344

you can do this with function explode():

$url = "http://example.com/search/tags/tag1/tag2/tag3";

list($url_part, $segments) = explode("/tags/", $url);

$tags_array = explode("/", $segments);

Upvotes: 1

safarov
safarov

Reputation: 7804

I am guessing you want to use in controller

$tags = $this->uri->uri_to_assoc();

Upvotes: 3

Related Questions