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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:58:49+00:00 2026-05-24T03:58:49+00:00

$test = array(‘<h1>text1</h1>’,'<h1><a href=#>text2</a><h1>’,'<h1>text3</h1><p>subtext3</p>’); In a long long texts, I use preg_split cut them

  • 0
$test = array('<h1>text1</h1>','<h1><a href="#">text2</a><h1>','<h1>text3</h1><p>subtext3</p>');

In a long long texts, I use preg_split cut them into small pieces. I want to remove only h1 tag wraped and without hyperlink.

I hope remove all the text looks like: <h1>text1</h1> //only h1 wraped and without hyperlink.

And remain <h1><a href="#">text2</a><h1>,<h1>text3</h1><p>subtext3</p>

  • 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-24T03:58:50+00:00Added an answer on May 24, 2026 at 3:58 am

    Use a loop to go through each array element and find each instance of the string “<“. Then look at the next 3 characters. If they’re “h1>” then you you have the correct tag. If you ever find a “<” that has a different 3 characters, then its not an “” HTML tag and you can remove this array object.

    To remove the given object from the array, you can use unset($array[$index]) and when you’re done I recommend using a sort to remove any index skips that may occur.

    You’ll want to use functions such as strpos to get the position of a string, and substr to get a subset of the given string. php.net is your friend 🙂

    Here is an example function which works with your $test array:

    <?php
    $test = array('<h1>text1</h1>','<h1><a href="#">text2</a><h1>','<h1>text3</h1><p>subtext3</p>');
    function removeBadElements(&$array) {
        foreach($array as $k => $v) {
            // $v is a single array element
            $offset = 0;
            do {
                $pos = strpos($v, '<', $offset);
                $offset = $pos + 1;
                if($pos === false) { break; }
    
                $tag = substr($v, $pos, 3);
                $next = substr($v, $pos+1, 1);
                if($next == '/') { continue; }
                if($tag == '<h1') { continue; }
                else {
                    unset($array[$k]);
                    break;
                }
            } while($offset + 2 < strlen($v));
        }
    }
    echo "\nORIG ARRAY:\n";
    print_r($test);
    removeBadElements($test);
    echo "\n\n-------\nMODIFIED ARRAY:\n\n";
    print_r($test);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

function returnsAnArray () { return array ('test'); } echo returnsAnArray ()[0]; generates a syntax
Can jQuery test an array for the presence of an object (either as part
I have an array that looks like: $fields = array( f1 => array(test), f2
How do I keep a certain number of elements in an array? function test($var)
<?PHP $signup_errors = array(); $signup_errors['captcha'] = 'test 1'; $signup_errors['something'] = 'test 2'; $signup_errors['another'] =
I have a string like this: TEST.DATA.Data.COR.Point,2;TEST.DATA.Data.COR.Point,5;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.WordTOFIND,18 I have a list of array with
i have this code $test = new test(); $test->var_test = array('one','two'); class test{ var
The following example shows what I want to do: >>> test rec.array([(0, 0, 0),
Test[] array = new Test[3]; array[0] = new RowBoat(Wood, Oars, 10); array[1] = new
I have test array of hex(radix 16) numbers var numbers = [01,02,a1]; and I

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.