I have a major WEIRD problem and I can't seem to understand it far less for solving it. On a form submit I am fwrite() a post variable containing HTML markup to and xml file (html is wrapped in <![CDATA[]]>. No encoding/ htmlentities is taking place). The xml file also contains custom namespace.
In my app when trying to edit this xml file I use the following code to retrieve and parse the xml file
Code: Select all
$x = file_actions($f,'r');
echo $x = str_replace("ts:","",file_get_contents(URL.'/data/articles/'.strtolower($article_id).'.xml'));
//exit;
$feed = '<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:ts="http://www.namspace.com/mynamespace"><title>Triniscene</title><link href="http://www.triniscene.com/"/><updated></updated><author><name>Triniscene</name></author><id>urn:</id>';
$xml = simplexml_load_string(sprintf("%s%s</feed>",$feed,$x),'SimpleXMLElement',LIBXML_NOCDATA);
print_r($xml);
$details = $xml->entry->content;However I get the following error
Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : expected '>' in
Warning: simplexml_load_string() [function.simplexml-load-string]: ted>2008-07-13T08:56:58Z</updated><author><name><![CDATA[yanna]]></name></author in on line 6
Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in
At first i thought it was the html markup in the CDATA but this isn't the case.
What is WEIRD about it is that if i "touched" the xml file myself and try reloading the above script....it works...no warning...
So i am thinking that I maybe fwrite() the file wrong....
is and xml file ascii or binary? What can be causing the warnings when the php fwrite() the file? why when I manually "touched" it it suddenly loads (i didnt change a thing in the xml file)?
the function i use to write the data to the file is
Code: Select all
function file_actions($file,$action,$string=false,$csv=false,$delimiter=false){
$ch = umask(0);
@chmod($file,0777);
if(strstr($action,"r")){
$fp = fopen($file,$action);
if($csv!=false){
if(!$delimiter)
$delimiter = ",";
while ($data = fgetcsv($fp, 1024, $delimiter))
$content[] = $data;
fclose($fp);
return $content;
}else{
$content = fread($fp,filesize($file));
fclose($fp);
}
}elseif(strstr($action,"w") || strstr($action,"a")){
$fp = fopen($file,$action);
//@flock($fp, LOCK_EX);
if(fwrite($fp,$string)){
//@flock($fp, LOCK_UN);
fclose($fp);
return true;
}else{
@flock($fp, LOCK_UN);
fclose($fp);
return false;
}
}
@chmod($file,0777);
if($content)
return $content;
else false;
}
Code: Select all
<entry><title type="text"><![CDATA[How to make a woman orgasm faster ]]></title><ts:subject><![CDATA[understanding orgasms]]></ts:subject><id>urn:uuid:ARTE8D858</id><ts:id>ARTE8D858</ts:id><published>2008-07-11T00:00:00Z</published><ts:date>2008-07-11</ts:date><updated>2008-07-13T12:18:12Z</updated><author><name><![CDATA[yanna]]></name></author<link rel="alternate" type="text/html" href="http://www.triniscene.com/tsv7/articles/?display=page&id=ARTE8D858" title="How to make a woman orgasm faster "/><category term="Sex and the Trini" label="Sex and the Trini"/><summary type="text"><![CDATA[When it comes to the female orgasm, most guys are confused.]]></summary><content type="html"><![CDATA[<p>When it comes to the female orgasm, most guys are confused. This isunderstandable considering that many men are clueless regarding thedifferent types of orgasms and stimulations that can be given, not tomention if a certain part of the vagina has to be manipulated in orderto give a woman an earth-shattering orgasm.<br /> <br /> Well, if you're among the bewildered, have heart; today's tip will help you <a href="http://www.askmen.com/love/love_tip_60/64_love_tip.html">understand the female genitalia</a> and the female orgasm inside and out.</p><h2>what happens?</h2><p>When a woman orgasms, regardless of which area of her body you'remanipulating, her body physically reacts in the same way. During anorgasm, she feels:</p> <ul><li>stimulation in her clitoris</li><li>her heart rate, blood pressure and breathing increase</li><li>tension builds within her pelvis</li><li>muscles contract throughout her body, especially in the vagina, uterus, rectum, and pelvic floor</li><li>tension is released upon orgasm</li></ul> <h2>blue clitoris</h2><p>Believe it or not, it is possible for women to get what is often called "<a href="http://www.askmen.com/love/dzimmer/15_love_answers.html">blue balls</a>" in men. As you know by now, <a href="http://www.askmen.com/love/love_tip_200/204_love_tip.html">the clitoris</a> and penis are remarkably similar after conception, but males go on to develop penises.<br /> <br /> If a woman gets incredibly turned on, her clitoris, like the penis,becomes engorged with blood. If the blood isn't released via orgasm,she will experience discomfort -- just as men do.<br /> <br /> So <a href="http://www.askmen.com/love/love_tip_150/161_love_tip.html">when you tease her</a>,you build up awesome tension, and when she finally orgasms, it will bean explosion of release. Keep in mind, however, that roughly 26% ofwomen have difficulty reaching orgasm. And usually, it's her own mentalblock that keeps her from reaching orgasm -- it's not you.</p><h2>different types</h2><p>It was Sigmund Freud who first suggested that there were two types offemale orgasm. However, sex researcher Alfred Kinsey refuted the claimand his view was that there is only one type of female orgasm.<br /> <br /> Others sexperts claim that women can have three types of orgasm:clitoral, vaginal and blended. But considering the latter is literallythe other two put together, I wouldn't necessarily classify it as atype.<br /> <br /> So who's right when it comes to female orgasms?</p>]]></content><ts:keywords>sex,orgasm,tips</ts:keywords></entry>