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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:16:16+00:00 2026-06-03T10:16:16+00:00

I have a complex string that represents database tables. And I need to extract

  • 0

I have a complex string that represents database tables. And I need to extract that database tables separately to process them.

Here’s the string example:

First table
    | | {{Категория}} | | {{Стоимость курсов}} | {{Стоимость учебного набора}} |
    | 1 | Взрослый | 1 уровень = 50ч  | 1~500 лей | 15 евро |
    | 2 |   Студент, Мастерант, Докторант | 1 уровень = 50ч | 1~000 лей | 15 евро |
    | 3 | Ученик | 1 уровень = 50ч  | 1~000 лей | 15 евро |
    | 4 | Пенсионер | 1 уровень = 50ч  | 1~000 лей | 15 евро |
text text  text text text text
    Second table:
        | | {{Вид курсов}} | | {{Стоимость курсов}}| {{Стоимость учебного набора}} |
        | 1 | dfgdfgdfg | 1 модуль | 500 лей |  0 |
        |^|^| 2 модуля | 900 лей | 0 |
        |^|^| 4 модуля | 1~500 лей | 0 |
        | 2 | fgdfgdfg | 12ч | 800 лей | 0 |
        | 3 | dfgdfgdfgdfg| 12ч | 900 лей | 0 |
        |^|^| Предварительный тест | 400 лей | 0 |
text text text text text text

I tried using this regexp: \|.+ but preg_match_all() simply dumps all the tables unseparated in the array. Any help, please? Thanks.

  • 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-03T10:16:16+00:00Added an answer on June 3, 2026 at 10:16 am

    As i see, you have a set of tables within one string. And you need to split string to tables. I assume you could split the string with the text, separating tables.

    <?php
    $s = <<<EOSTR
    First table
        | | {{Категория}} | | {{Стоимость курсов}} | {{Стоимость учебного набора}} |
        | 1 | Взрослый | 1 уровень = 50ч  | 1~500 лей | 15 евро |
        | 2 |   Студент, Мастерант, Докторант | 1 уровень = 50ч | 1~000 лей | 15 евро |
        | 3 | Ученик | 1 уровень = 50ч  | 1~000 лей | 15 евро |
        | 4 | Пенсионер | 1 уровень = 50ч  | 1~000 лей | 15 евро |
    text text  text text text text
        Second table:
            | | {{Вид курсов}} | | {{Стоимость курсов}}| {{Стоимость учебного набора}} |
            | 1 | dfgdfgdfg | 1 модуль | 500 лей |  0 |
            |^|^| 2 модуля | 900 лей | 0 |
            |^|^| 4 модуля | 1~500 лей | 0 |
            | 2 | fgdfgdfg | 12ч | 800 лей | 0 |
            | 3 | dfgdfgdfgdfg| 12ч | 900 лей | 0 |
            |^|^| Предварительный тест | 400 лей | 0 |
    text text text text text text
    EOSTR;
    
    $a = null;
    $a = preg_split('/^(?:.(?<!\|))*$/xm', $s);
    var_dump($a);
    

    Just like here: http://ideone.com/VCt4f (using this question). This will give you this:

    array(5) {
      [0]=>
      string(0) ""
      [1]=>
      string(506) "
        | | {{Категория}} | | {{Стоимость курсов}} | {{Стоимость учебного набора}} |
        | 1 | Взрослый | 1 уровень = 50ч  | 1~500 лей | 15 евро |
        | 2 |   Студент, Мастерант, Докторант | 1 уровень = 50ч | 1~000 лей | 15 евро |
        | 3 | Ученик | 1 уровень = 50ч  | 1~000 лей | 15 евро |
        | 4 | Пенсионер | 1 уровень = 50ч  | 1~000 лей | 15 евро |
    "
      [2]=>
      string(1) "
    "
      [3]=>
      string(466) "
            | | {{Вид курсов}} | | {{Стоимость курсов}}| {{Стоимость учебного набора}} |
            | 1 | dfgdfgdfg | 1 модуль | 500 лей |  0 |
            |^|^| 2 модуля | 900 лей | 0 |
            |^|^| 4 модуля | 1~500 лей | 0 |
            | 2 | fgdfgdfg | 12ч | 800 лей | 0 |
            | 3 | dfgdfgdfgdfg| 12ч | 900 лей | 0 |
            |^|^| Предварительный тест | 400 лей | 0 |
    "
      [4]=>
      string(0) ""
    }
    

    When you’re done extracting tables you could simply split them to columns with

    // $a = preg_split...
    
    foreach ($a as $table) {
        if (!strlen(trim($table)))
             continue;
    
        $rows = preg_split('/\n/', $table);
    
        foreach ($rows as $row) {
            if (!strlen(trim($row)))
                continue;
    
            $columns = preg_split('/\|/', $row);
    
            // work with $columns array
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Example: I have a complex method that does a lot of stuff, and at
I have a data structure that represents C# code like this: class Namespace: string
I have a complex script that takes variables from files and uses them to
I have a complex database conversion console app that reads from an old database,
I have implemented a sorting algorithm for a custom string that represents either time
I have a class that represents a pretty complex object. The objects can be
I have a complex RIA client that communicates with a WCF SOAP web service,
I have some complex regular expressions which I need to comment for readability and
I have a complex sql query that I have in a stored procedure and
Take this simple, contrived example: UserRepository.GetAllUsers(); UserRepository.GetUserById(); Inevitably, I will have more complex queries,

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.