메인>>유머

네이버 환율 파싱

2022-01-25 16:55:00 2702

네이버 환율 파싱 소스를 에서 참고하여 작성하여 웹호스팅(카페24 이용 중)에 업로드 하였을 때는 환율정보가 잘 나옵니다...그런데 내부서버(오토셋 10.7.2)로 업로드하면 Warning: Illegal string offset 'USD' in 파일주소 on line 59 등의 에러가 발생합니다. 아마 PHP버젼이 달라서 인 듯합니다. (카페24는 PHP 5.3, 오토셋은 PHP 7.2) 이 경우 다음과 같이 변경하여 적용하니 이상없이 잘 작동되네요.... 참고하시기 바랍니다. (제 질문에 답변주신 슈와이님께 감사드립니다..) .*?<\/[\s]*tbody>/s", $res, $tbody); if(!is_array($tbody)) return 'false'; preg_match_all('#(.*?)<\/[\s]*tr>#s', $tbody[0], $tr); if(!is_array($tr)) return 'false'; $Data = array(); foreach($tr[0] as $k=>$v) { unset($td, $akey); preg_match_all('#(.*?)<\/td>#s', $v, $td); $td = $td[0]; $akey = preg_replace('/([\xEA-\xED][\x80-\xBF]{2})+/', '', strip_tags($td[0])); $akey = trim(str_replace('JPY (100)', 'JPY', $akey)); $akey = trim(str_replace('100', '', $akey)); if(!$akey) return 'false'; $Data[$akey]['통화명'] = trim(strip_tags($td[0])); $Data[$akey]['매매기준율'] = str_replace(',', '', trim(strip_tags($td[1]))); $Data[$akey]['현찰살때'] = str_replace(',', '', trim(strip_tags($td[2]))); $Data[$akey]['현찰팔때'] = str_replace(',', '', trim(strip_tags($td[3]))); $Data[$akey]['송금보낼때'] = str_replace(',', '', trim(strip_tags($td[4]))); $Data[$akey]['송금받을때'] = str_replace(',', '', trim(strip_tags($td[5]))); $Data[$akey]['미화환산율'] = str_replace(',', '', trim(strip_tags($td[6]))); } return $Data; } $Data = Ncurrency(); ?> 읽어주셔서 감사합니다.