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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:26:48+00:00 2026-06-12T15:26:48+00:00

Possible Duplicate: Get content between two strings PHP I am trying to create a

  • 0

Possible Duplicate:
Get content between two strings PHP

I am trying to create a php function that will return an array of all occurrences of text between two substrings. I am useless at regular expression and would find this very handy, I’m sure there is already a very nice one out there but I can’t find it.

    function getAllBetweenStr($input, $start, $end)
    {
         //DO STUFF

         //RETURN ARRAY
    }


$inputStr ="<a href='http://formaco4/en/abc' class='currentLink' hreflang='en'>abc1/a>
<a href='http://formaco4/en/abc/b1'  hreflang='en'>abc2</a>
<a href='http://formaco4/en/abc/b2'  hreflang='en'>abc3</a>
<a href='http://formaco4/en/abc/b3'  hreflang='en'>abc4</a>";


$linkStr = array();
$linkStr = getAllBetweenStr($inputStr, "http://formaco4/en/'", "'  hreflang")

The return array would be like this
Array([0] => “abc/b1”, [1] => “abc/b2”, … , [n] => “gingers/rule”)

I have this function already if it helps:

    function getBetweenStr($string, $start, $end)
    {
        $string = " ".$string;
        $ini = strpos($string,$start);
        if ($ini == 0) return "";
        $ini += strlen($start);    
        $len = strpos($string,$end,$ini) - $ini;
        return substr($string,$ini,$len);
    }
  • 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-12T15:26:49+00:00Added an answer on June 12, 2026 at 3:26 pm

    I believe something like this will work – It uses preg_match_all to capture anything between the two $start and $end strings.

    function getBetweenStr($string, $start, $end)
    {
        preg_match_all( '/' . preg_quote( $start, '/') . '(.*?)' . preg_quote( $end, '/') . '/', $string, $matches);
        return $matches[1];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Get content between two strings PHP Ok, here is my delima: here
Possible Duplicate: Get a list of dates between two dates This is my sql:
Possible Duplicate: Get content within a html tag using php and replace it after
Possible Duplicate: PHP Regex Get Text Between BBCode Tags I have a text like:
Possible Duplicate: Get the Files inside a directory Is there a function that can
Possible Duplicate: Getting content using wikipedia API Using PHP, how do I get the
Possible Duplicate: Get URL of ASP.Net Page in code-behind I'm trying to hold current
Possible Duplicate: get name of current PHP script in include file Can an included
Possible Duplicate: get image from base64 string I tried header('Content-Type: image/png'); echo base64_decode($data);` But
Possible Duplicate: Data transfer from JavaScript to PHP. How can i get the browser's

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.