That part of the loop keeps writing wrong.
Requirements are as follows
Read A.txt content is
111,2222
333,4444
555,7777
Such a format
If the value of $goods_id is equal to the value in front of one of the rows, then the output is converted to a later output, such as $goods _id=111, then the replacement outputs $goods_id=2222
Reply content:
That part of the loop keeps writing wrong.
Requirements are as follows
Read A.txt content is
111,2222
333,4444
555,7777
Such a format
If the value of $goods_id is equal to the value in front of one of the rows, then the output is converted to a later output, such as $goods _id=111, then the replacement outputs $goods_id=2222
$goods_id = 111;$handle = fopen("f:/test.txt", "r");while (!feof($handle)) { $line = fgets($handle, 4096); //echo $line."
"; $str = explode(",",$line); if($str[0] == $goods_id ){ echo $str[1]; }} fclose($handle);
`
function getGoodsIpMap(){ $fh = fopen('a.txt', 'r'); $goodsMap = array(); while($line=fgets($fh)!==false) { if(empty($line)) { continue; } list($oldId, $newId) = explode(',',trim($line)); $goodsMap[$oldId] = $newId; } fclose($fh);}$goodsIdMap = getGoodsIpMap();$newId = isset($goodsIdMap[$goodsId]) ? $goodsIdMap[$goodsId] : $goodsId;
`