Jump to content

Yuval200

Members
  • Posts

    79
  • Joined

  • Last visited

Yuval200's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. I really liked http://www.colourlovers.com.. I also really liked the programming of the site.
  2. Oh, sorry, thanks again :)I'm doing fine now XML wise, I only have a small OOP issue. I have read about the __destruct function. As I understood, the function works when the parser finish parsing the code and there is no more HTML to be wrote. Code-wise it works great. class xml { public $file, $error, $xmlfile = array(); function __construct($xmlFile) { $this->error = "<b>Class " . __CLASS__ . ":</b>"; if (!is_array($xmlFile)) die($this->error." \$xmlFile must be entered as an array."); $this->file = array(); foreach($xmlFile as $number => $xml) { $xml = "data/{$xml}"; $this->xmlfile[] = $xml; if (!file_exists($xml)) die($this->error." file {$xml} (<em>number {$number}</em>) doesn't exist."); $this->file[] = new SimpleXMLElement($xml, null, true); //Loads the xml files, one at a time. } return $this->file; } function updateXML(&$xmlPath, $xmlValue, $attributeName = false) { if (!$attributeName) return $xmlPath[0] = $xmlValue; return $xmlPath[$attributeName] = $xmlValue; } function __destruct() { foreach($this->xmlfile as $number => $xml) { if(!$this->file[$number]->asXML($xml)) die($this->error." Could not update file {$xml} (number {$number})."); $this->file[$number]->asXML($xml); die("INDEED"); } }} (just refer to the __destruct function, it's the only thing changed). The interesting part is that when I change the function name to something like __fhfdsdsbfdsa and then call it using $classxml->__dfkmdmbldflbndfalbd() it works great. Why? Should I not use __destruct for this case?Thanks
  3. So I need to save all I did when I finish working with the XML document? How do I do this?
  4. Heh, that was a stupid mistake.. THANKS ALOT :)Now, I have a weird error.. This is the function: function updateXML(&$xmlPath, $xmlValue, $attributeName = false) { if (!$attributeName) return $xmlPath[0] = $xmlValue; return $xmlPath[$attributeName] = $xmlValue; } And the code: $classxml->updateXML($xml[0]->post[0]->poster, "66", "id");$classxml->updateXML($xml[0]->post[0]->content, "d");echo $xml[0]->post[0]->poster['id'] . "\n" . $xml[0]->post[0]->content; With the code above it changes the content, but the thing I noticed is when I delete the first line, the value of "id" returns to 1337, and when removing the second line, content value returns to be "Post Content". Why?
  5. Thanks ALOT man ! I added [0] after $xmlPath and it works great now .Now I have a problem with attributes, I updated my XML document: <?xml version="1.0" encoding="utf-8"?><posts> <post> <poster id="1337">Yuval</poster> <content>Post content</content> </post></posts> I am trying to echo the following line: echo $xml[0]->post[0]->content['id']; Doesn't work, I have tried var_dump: var_dump($xml[0]->post[0]->content['id']);var_dump((string) $xml[0]->post[0]->content['id']); First line returns null, and the second line returns a string with the length of 0. I have tried to chage content['id'] to content[0]['id'] But it still doesn't work.. Can you please help me?Thanks
  6. updateXML: function updateXML(&$xmlPath, $xmlValue, $attributeName = false) { if (!$attributeName) { echo "XMLPath:\n"; var_dump($xmlPath); echo "\nXMLValue:\n"; var_dump($xmlValue); echo "\nAttrName:\n"; var_dump($attributeName); echo "!\n"; return $xmlPath = $xmlValue; } elseif (trim($attributeName)) { //$this } } It returns the following:
  7. Yuval200

    xml and php

    After reading the XML tutorial, I recommend you use the SimpleXMLElement class
  8. Thanks , but it still doesn't work.. the function looks like this now: function updateXML(&$xmlPath, $xmlValue, $attributeName = false) { if (!$attributeName) return $xmlPath = $xmlValue; elseif (trim($attributeName)) { //$this } }
  9. Sorry, I solved that issue some time ago, now I have a new one with functions; To change the value of a tag, I need to do the following: class xml { public $file; protected $error; function __construct($xmlFile) { $this->error = "<b>Class " . __CLASS__ . ":</b>"; if (!is_array($xmlFile)) die($this->error." \$xmlFile must be entered as an array."); $this->file = array(); foreach($xmlFile as $number => $xml) { $xml = "data/{$xml}"; if (!file_exists($xml)) die($this->error." file {$xml} (<em>number {$number}</em>) doesn't exist."); $this->file[] = new SimpleXMLElement($xml, null, true); //Loads the xml files, one at a time. } } function updateXML($xmlPath, $xmlValue, $attributeName = false) { if (!$attributeName) return $xmlPath = $xmlValue; elseif (!trim($isElement) && trim($attributeName)) { //$this } }}$classxml = new xml(array('posts.xml'));$xml = $classxml->file; Now, I am using the following function: $classxml->updateXML($xml[0]->post[0]->content, "d"); But it doesn't work, Why ?Thanks in advance :}
  10. Lol, you haven't hurt anything .Now, if someone could just answer my question
  11. Yeah, I remember using this way some time ago, forgot about it.. Haha, I'm not that of a beginner, Printing an array in a foreach loop isn't to difficult for me .--Another issue, how do I update existing tags? I have tried the following: echo $xml[0]->post[0]->content;$xml[0]->post[0]->content = "NOT Post content"; But it doesn't seem to work..Thanks
  12. Hello guys .Well, I have the following issue; I am using the following XML document: <?xml version="1.0" encoding="utf-8"?><posts> <post> <poster>Yuval</poster> <content>Post content</content> </post></posts> Now, I use the SimpleXMLElement class, and it really all works fine, I just don't understand something.When I use the following code: echo $xml[0]->children()->children(); It works two, and it writes "Yuval". My question: how can I access the second element (content)? I have tried several ways but nothing seems to work.Thanks
  13. PLEASE, can anyone give me an example with the whole thing? PLEASE
  14. Thanks, thing is.. $regex_output will be something like this:$regex_output = preg_replace("blabla", "blabla", $_POST['bla']) AND THAT IS WHAT I AM ASKING!How can I tell PHP that I want to explode the sub-string INSIDE the box. Please, can anyone help me.
  15. Thanks.. I know regex stuff, but again, can I please have an example on how to perform this?
×
×
  • Create New...