这是我的xml文件。(我没有创建此文件的解析器的编辑能力……很高兴我在下面问这个问题)。
<?xml version="1.0" encoding="UTF-8"?>
<JobSearchResults LookID="arkansas">
<!-- Served from qs-b-02.oc.careercast.com -->
<QueryString>clientid=arkansas&stringVar=xmlString&pageSize=200&searchType=featured&outFormat=xml</QueryString>
<channel>
<title>JobsArkansas Listings</title>
<items></items>
</channel>
<item>
<JobID>73451732</JobID>
<Title>Radiology</Title>
<Employer>Baptist-Health </Employer>
<Location>LITTLE ROCK, AR</Location>
<Description><![CDATA[IMMEDIATE OPENINGS for:Diabetes Patient Educator, RN Community Education Nurse-RN Baptist Health Community Outreachâ¢Diabetes Patient Educator, RN: Full-time: 8am-5pm Minimum Requirements:â¢Requires graduation from a state approved school/college of Nursingâ¢Current licensure by theAR State Board of Nursing. â¢2+ years bedside experience preferred. â¢Certified Diabetes Educator certificate preferred. â¢Community Education Nurse - RNMinimum Requirements (PRN: Varies):â¢Current RN license & 2 years clinical experience. â¢Current CPR certification. Apply online at: baptist-health.com/jobs]]></Description>
<LookID>arkansas</LookID>
<Url>http://jobs.arkansasonline.com/careers/jobsearch/detail/jobId/73451732/viewType/featured</Url>
</item>
<item>
<JobID>66703190</JobID>
<Title>Telemarketing Agents</Title>
<Employer>Arkansas Democrat Gazette </Employer>
<Location>Bryant, AR</Location>
<Description><![CDATA[Telemarketing Agents Needed Position is part-time Starting at $9.00/hour Plus Bonus! Looking for dependable and professional applicants. We are a drug and smoke free company located in Bryant. Hours: Mon-Fri 4:30pm to 8:30pm and Sat. 9am to 6pm. Send resumes to: clewis@wehco.com or P.O. Box 384 Bryant, AR 72089 Arkansas Democrat Gazette Arkansas' Largest NewspaperCLICK THE IMAGE TO VIEW THE AD]]></Description>
<LookID>arkansas</LookID>
<Url>http://jobs.arkansasonline.com/careers/jobsearch/detail/jobId/66703190/viewType/featured</Url>
</item>
</JobSearchResults>
sas</LookID>
<Url>http://jobs.arkansasonline.com/careers/jobsearch/detail/jobId/73004973/viewType/featured</Url>
</item>
</JobSearchResults>
我使用以下php代码打开上述xml文件,并取出以下内容:
sas公司
http://jobs.arkansasonline.com/careers/jobsearch/detail/jobId/73004973/viewType/featured
</JobSearchResults>
然而,下面的php代码:
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
// Load File
// $today = date('Ymd');
$file = '/Users/jasenburkett/Sites/jobsark/feed' . '.xml';
$newfile = '/Users/jasenburkett/Sites/jobsark/feed' . '.xml';
$file_contents = file_get_contents($file);
$data = $file_contents;
$parts = explode("</JobSearchResults>", $data);
// Save File
file_put_contents($newfile, $data);
?>
这是有效的,但是它会删除第一个之后的所有内容
</JobSearchResults>
我想保留最后一个。。。
你知道我哪里错了吗?