Hello I need to search a file and return the values Example The file abc.txt <master:vivek> <reseller:vivek11> <reseller:vivek22> <reseller:vivek33> Code (markup): Ok, What I want is , to read this file and get the values , vivek, vivek11,vivek22, and vivek33 Like $master = "vivek" $reseller[0] = "vivek11" $reseller[1] = "vivek22" $reseller[2] = "vivek33" Can anybody help me ? Thank you
$lines = file('abc.txt'); foreach ($lines as $line) { if (preg_match('/<master:([^>]+)/i', $line, $matches)) $master = trim($matches[1]); if (preg_match('/<reseller:([^>]+)/i', $line, $matches)) $reseller[] = trim($matches[1]); } Code (markup):
Or, $lines = file('abc.txt'); foreach ($lines as $line) { if ($line)<>""){ $arr = explode(":",$line); // split by : $arr[0]=substr($arr[0],2,strlen($arr[0])-1); // delete < $arr[1]=substr($arr[1],1,strlen($arr[1])-1); // delete > if ($arr[0] == "master" ){ echo 'master = "' . $arr[1] ; }elseif ($arr[0] == "reseller" ){ ....... } } PHP: You can cmplete, I just give the idea