Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3221742
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:54:41+00:00 2026-05-17T15:54:41+00:00

I have custom tags [tag val=100][/tag] . How do I get val and whatever

  • 0

I have custom tags [tag val=100][/tag]. How do I get val and whatever goes between the tags?

ex:

[tag val=100]apple[/tag]  

value1 = 100
value2 = apple

edit: what if I had multiple items inside the tag
ex:

[tag val=100 id=3]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:54:41+00:00Added an answer on May 17, 2026 at 3:54 pm

    If you have a string like that in your question, you can use preg_match instead of preg_match_all:

    $str = "[tag val=100]apple[/tag]";
    
    preg_match("/\[.+? val=(.+?)\](.+?)\[\/.+?\]/", $str, $matches);
    
    $value = $matches[1];    // "100"
    $content = $matches[2];  // "apple"
    

    Update: I see you might have multiple attributes in each element. In that case, this should work:

    // captures all attributes in one group, and the value in another group
    preg_match("/\[.+?((?:\s+.+?=.+?)+)\](.+?)\[\/.+?\]/", $str, $matches);
    
    $attributes = $matches[1];
    $content = $matches[2];
    
    // split attributes into multiple "key=value" pairs
    $param_pairs = preg_split("/\s+/", $attributes, -1, PREG_SPLIT_NO_EMPTY);
    // create dictionary of attributes
    $params = array();
    foreach ($param_pairs as $pair) {
        $key_value = explode("=", $pair);
        $params[$key_value[0]] = $key_value[1];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a <filter:filters> tag and a <filter:filter> tag. These are JSP custom tags.
I have a custom jsp tag like this: <a:customtag> The body of the custom
I have a lot of strings containing custom tags: hello {RT|12} world {RT|465} this
I have a bunch of java custom tags that use spring managed beans.. since
I have a custom tag in Jinja2 that I want to output something only
I have gone through the (painful) process of writing a custom template tag for
i have an xml which has some custom tags below is the xml: <Point
I have custom Rythm template tag (sayHi.html) which I want to call from parent
I have a file with some custom tags and I'd like to write a
I have an XML file with a bunch of data contained by custom tags.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.