Question

i am having one probelm cant cant figure it out how i can proceed. I have string like

  "Coolman United States Member Since January 2013 Loans  114.01 Active  66.00 Repaid    Credentials 2 followers eBay windchester 42 Friends 2"

now with php i need to find the user name that is "Coolman" country, member sience, loans, active, repaid, followers.

I know with preg_replace, regex i can find the exact text that is matched. but the problem is there are hundreds of data like this similar pattern, with different username with different countries, different dates etc so how can i have result like this?

username : Coolman country:United State Member Since: January 2013 and so on...

Thanks for your help

Was it helpful?

Solution

Here is something that may help you:

function GetBetween($content,$start,$end){
    $r = explode($start, $content);
    if (isset($r[1])){
        $r = explode($end, $r[1]);
        return $r[0];
    }
    return '';
}

$string="Coolman United States Member Since January 2013 Loans  114.01 Active  66.00 Repaid    Credentials 2 followers eBay windchester 42 Friends 2";
echo GetBetween($string,"Member Since "," Loans");

$wh = strpos($string," ");
$username = substr($string,0,$wh);
$country = substr($string,$wh,strpos($string," Member Since")-$wh);

I assume here that the username is always one word.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top