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 8761563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:18:54+00:00 2026-06-13T15:18:54+00:00

I have strings of data in a field named content , one record may

  • 0

I have strings of data in a field named content, one record may look something like:

loads of text ... [attr1] some text [attr2] more text [attr3] more text etc...

What I’m looking to do is get all the text within the square brackets; so that I can put it into a PHP array. Is this even possible with mySql?

I’ve seen the following post: Looking to extract data between parentheses in a string via MYSQL, but they are looking to only extract one value from between their parentheses, I have an unknown number of them. After reading that post I’ve though of doing something like the following;

SELECT substr(content,instr(content,"["), instr(content,"]")) as attrList from myTable

Which would grab me the following:

[attr1] some text [attr2] some more text [attr3]

and I can use PHP to strip the rest of the text out and then explode the string into an array, but is there a better way to do this just using mySql where I can retrieve something like:

[attr1][attr2][attr3]

I was thinking perhaps regex, but I see that just returns a true of false which doesn’t help me a lot.

  • 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-06-13T15:18:55+00:00Added an answer on June 13, 2026 at 3:18 pm

    After even more research, I’m not sure it’s possible in mySql, and I might need the results in string or array form depending on where I’m using them in my app.

    So I’ve created a new method to return the list after I’ve got the data from the database (with a little help from this post: PHP: Capturing text between square brackets):

    public function attrList($array=false)
    {
        preg_match_all("/\[.*?\]/",$this->content,$matches);
    
        $params = str_replace(array('[',']'),'',$matches[0]);
    
        return ($array===false) ? implode(', ',$params) : $params;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to work with strings which may contain Lat/Long data, like this: $query
Let's say I have two strings: one is XML data and the other is
I have the following JavaScript data structure. a[] is an array with text strings
I have array of strings, String[] data and it's 10 elements has value P
I have question about interpreting strings as packed binary data in C++. In python,
I have the following data in my database (comma separated strings): word, test, hello
I have some data structures: all_unordered_m is a big vector containing all the strings
I have a Hashtable of type Hashtable I've loaded several strings as keys, one
In my MySql i am having my data field as longblob i would like
I have some data which I am formatting like this: // ... imagine populating

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.