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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:59:33+00:00 2026-06-07T03:59:33+00:00

I have a HTML content like this one some html text [link id=1] some

  • 0

I have a HTML content like this one

some html text [link id="1"]  some html text 
some html text [link id="2"]  some html text 
some html text [link id="3" stat="y"]  some html text 
some html text [link id="4" stat="y"]  some html text 

I’m using

var_dump(preg_match_all('/\[link([^\[]+)\]/',$html_tags, $result));

to extract [link] tags from it and it is giving me an array like this

array(2) {
  [0]=> array(4) {
    [0]=> string(13) "[link id="1"]"
    [1]=> string(13) "[link id="2"]"
    [2]=> string(21) "[link id="3" stat="y"]"
    [3]=> string(21) "[link id="4" stat="y"]"
  }
  [1]=> array(4) {
    [0]=> string(7) " id="1""
    [1]=> string(7) " id="2""
    [2]=> string(15) " id="3" stat="y""
    [3]=> string(15) " id="4" stat="y""
  }
}

Can anyone please tell me how I can get the result like this

array (1){
    [0]=> array (4) {
        [0] => array (2){
            [id]  => string(1) "1"
            [stat] => string(0) ""
        }
        [1] => array (2){
            [id]  => string(1) "2"
            [stat] => string(0) ""
        }
        [2] => array (2){
            [id]  => string(1) "3"
            [stat] => string(1) "y"
        }   
        [3] => array (2){
            [id]  => string(1) "4"
            [stat] => string(1) "y"
        }   
    }
}
  • 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-07T03:59:35+00:00Added an answer on June 7, 2026 at 3:59 am

    You can use custom written function and array_map.

    http://php.net/manual/en/function.array-map.php

    //first flatten array
    $array = $array[1];
    array_map("passone", $array);
    array_map("passtwo", $array);
    
    
    function passone ($n) {
        return substr($n, 1);
    }
    
    function passtwo ($n) {
        $nx = explode(" ", $n);
        preg_match("link=\"(.*?)\"", $nx[0], $matches);
        $ret['id'] = $matches[0];
        if (!empty($nx[1]))
        {
            $times = preg_match("stat=\"(.*?)\"", $nx[1], $matches);
            if ($times != 0)
            {
            $ret['stat'] = $matches[0];
            }
        }
        return $ret;
    }
    

    This should work for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some HTML that looks like this: <div class=product> Content In Here <div
I have some text content (read in from the HTML using jQuery) that looks
I want to parse a html content that have something like this: <div id=sometext>Lorem<br>
i have my html something like this... <div class = content> <div class =
OK I have backgrounds set up like this: HTML <div id=container> <div id=content> CONTENT
I would like to extract some text from an html file using Regex. I
I have a master page that has two content sections like this (left some
If I have HTML content in a variable like so: var data = <div
I have the following HTML: <div id=mydiv> </div> I would like to load content
Suppose we have this html content, and we are willing to get Content1, Content2,..

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.