php在xml文件上爆炸 [英] php explode on xml file

查看:89
本文介绍了php在xml文件上爆炸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我拥有的xml文件. (我不具备创建该文件的解析器的编辑功能,因此,为什么在下面问我这个问题.)

Here is the xml file I have. ( I do not have editing abilities of the parser that creates this file... so hince why I am asking my question below).

<?xml version="1.0" encoding="UTF-8"?>
<JobSearchResults LookID="arkansas">
<!-- Served from qs-b-02.oc.careercast.com -->
<QueryString>clientid=arkansas&amp;stringVar=xmlString&amp;pageSize=200&amp;searchType=featured&amp;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文件,并删除以下内容: 萨斯 http://jobs.arkansasonline.com/careers/jobsearch/detail /jobId/73004973/viewType/功能

I am using the following php code to open the above xml file, and take out the following: sas http://jobs.arkansasonline.com/careers/jobsearch/detail/jobId/73004973/viewType/featured

</JobSearchResults>    

但是下面的php代码:

However the php code below:

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>之后的所有内容,而我想保留最后一个...

This works, however it deletes everything after the first </JobSearchResults> and I want to keep the very last one...

有什么想法我要去哪里吗?

Any ideas where i am going wrong?

推荐答案

如果要查找的是清理损坏的XML文件的方法,则只需添加运行爆炸时丢失的字符串即可.都有点黑,但是行得通.

If what you are looking for is a way to cleanup the corrupt XML file, you can just add the string that gets missing when the explode is run. It is all a bit hackish, but it works.

$file = '/Users/jasenburkett/Sites/jobsark/feed.xml';
$data = file_get_contents($file);

$split = "</JobSearchResults>";   // Split on this
$parts = explode($split, $data);  // Make the split
$cleanedXml = $parts[0];          // Use first part
$cleanedXml .= $split;            // Put back last ending tag

file_put_contents($file, $cleanedXml);

这篇关于php在xml文件上爆炸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆