Dec 1, 2007
3,591
2
0
39
in hear
kawru hari dannawada xml file ekak edit karanna
mata one me xml file ekata image kiyana tag ekak aluthen add karanna
php use karala

<?xml version="1.0" encoding="UTF-8"?>

<gallery>
<image url="Flower Photo 1.jpg" />
<image url="Flower Photo 2.jpg" />
<image url="Flower Photo 3.jpg" />
<image url="Flower Photo 4.jpg" />
<image url="Flower Photo 5.jpg" />
<image url="Flower Photo 6.jpg" />
<image url="Flower Photo 7.jpg" />
<image url="Flower Photo 8.jpg" />
<image url="Flower Photo 9.jpg" />
<image url="Flower Photo 10.jpg" />
</gallery>
ane dannawanam loku udawwak !:(:(
 

galleline

Well-known member
  • Feb 8, 2009
    6,088
    179
    63
    ********
    To add to what others have said, you can't directly put a $_GET or $_POST value into a variable then into an attribute using SimpleXML. You must first convert it to an integer.

    This will NOT work
    <?php
    $page_id = $_GET['id'];
    echo $xml->page[$page_id]
    ?>

    However, this WILL work and is much simpler then using (string) or other methods.
    <?php
    $page_id = intval($_GET['id']);
    echo $xml->page[$page_id]
    ?>
     
    Dec 1, 2007
    3,591
    2
    0
    39
    in hear
    galleline said:
    To add to what others have said, you can't directly put a $_GET or $_POST value into a variable then into an attribute using SimpleXML. You must first convert it to an integer.

    This will NOT work
    <?php
    $page_id = $_GET['id'];
    echo $xml->page[$page_id]
    ?>

    However, this WILL work and is much simpler then using (string) or other methods.
    <?php
    $page_id = intval($_GET['id']);
    echo $xml->page[$page_id]
    ?>
    machan eka man dannawa mata one file eka edit karanna bt thanx...
     

    hirushan

    Member
    May 21, 2007
    5,957
    32
    0
    40
    Edinton Furniture->Moratumulla
    HTML:
    XML Code: file name - employees.xml
    
    <?xml version="1.0" encoding="iso-8859-1"?>
    <employees>
      <employee>
      <name>Mark</name>
      <age>27</age>
      <salary>$5000</salary>
      </employee>
      <employee>
      <name>Jack</name>
      <age>25</age>
      <salary>$4000</salary>
      </employee>
      </employees>


    PHP:
    <?php 
      $employees = array(); 
      $employees [] = array( 
      'name' => 'Albert', 
      'age' => '34', 
      'salary' => "$10000" 
      ); 
      $employees [] = array( 
      'name' => 'Claud', 
      'age' => '20', 
      'salary' => "$2000" 
      ); 
       
      $doc = new DOMDocument(); 
      $doc->formatOutput = true; 
       
      $r = $doc->createElement( "employees" ); 
      $doc->appendChild( $r ); 
       
      foreach( $employees as $employee ) 
      { 
      $b = $doc->createElement( "employee" ); 
       
      $name = $doc->createElement( "name" ); 
      $name->appendChild( 
      $doc->createTextNode( $employee['name'] ) 
      ); 
      $b->appendChild( $name ); 
       
      $age = $doc->createElement( "age" ); 
      $age->appendChild( 
      $doc->createTextNode( $employee['age'] ) 
      ); 
      $b->appendChild( $age ); 
       
      $salary = $doc->createElement( "salary" ); 
      $salary->appendChild( 
      $doc->createTextNode( $employee['salary'] ) 
      ); 
      $b->appendChild( $salary ); 
       
      $r->appendChild( $b ); 
      } 
       
      echo $doc->saveXML(); 
      $doc->save("write.xml") 
      ?>
     
    Dec 1, 2007
    3,591
    2
    0
    39
    in hear
    hirushan said:
    fwrite function eka use karalda oka karanna ona??
    man ehema try ekak dunn eth ethakota machan mehema liyawenne
    <?xml version="1.0" encoding="UTF-8"?>

    <gallery>
    <image url="Flower Photo 1.jpg" />
    <image url="Flower Photo 2.jpg" />
    <image url="Flower Photo 3.jpg" />
    <image url="Flower Photo 4.jpg" />
    <image url="Flower Photo 5.jpg" />
    <image url="Flower Photo 6.jpg" />
    <image url="Flower Photo 7.jpg" />
    <image url="Flower Photo 8.jpg" />
    <image url="Flower Photo 9.jpg" />
    <image url="Flower Photo 10.jpg" />
    </gallery>
    <image url="Flower Photo 11.jpg" />
    eth mata one

    <?xml version="1.0" encoding="UTF-8"?>

    <gallery>
    <image url="Flower Photo 1.jpg" />
    <image url="Flower Photo 2.jpg" />
    <image url="Flower Photo 3.jpg" />
    <image url="Flower Photo 4.jpg" />
    <image url="Flower Photo 5.jpg" />
    <image url="Flower Photo 6.jpg" />
    <image url="Flower Photo 7.jpg" />
    <image url="Flower Photo 8.jpg" />
    <image url="Flower Photo 9.jpg" />
    <image url="Flower Photo 10.jpg" />
    <image url="Flower Photo 11.jpg" />
    </gallery>
     

    Faulkner

    Member
    Apr 5, 2009
    285
    0
    0
    34
    Moscow, Russia
    MagmificentROO said:
    kawru hari dannawada xml file ekak edit karanna
    mata one me xml file ekata image kiyana tag ekak aluthen add karanna
    php use karala


    ane dannawanam loku udawwak !:(:(

    <html>:):):):):)
    <body>

    <iOkay here you go then just type maccho>

    <?php
    $file=fopen("Flower Photo 1.jpg","a");
    ?>
    <?php
    $file=fopen("Flower Photo 1.jpg","br");
    ?>
    <?php
    $file=fopen("Flower Photo 1.jpg","c");
    ?>
    <?php
    $file=fopen("Flower Photo 1.jpg","d");
    ?>
    <?php
    $file=fopen("Flower Photo 1.jpgt","e");
    ?>
    <?php
    $file=fopen("Flower Photo 1.jpg","f");
    ?>
    <?php
    $file=fopen("Flower Photo 1.jpg","g");
    ?>
    <?php
    $file=fopen("Flower Photo 1.jpg","h");
    ?>
    <?php
    $file=fopen("Flower Photo 1.jpg","i");
    ?>
    <?php
    $file=fopen("Flower Photo 1.jpg","j");
    ?>

    </body>
    </html>
     

    Faulkner

    Member
    Apr 5, 2009
    285
    0
    0
    34
    Moscow, Russia
    If this file's name ImageGallery.xml

    <?xml version="1.0" encoding="UTF-8"?>

    <gallery>
    <image url="Flower Photo 1.jpg" />
    <image url="Flower Photo 2.jpg" />
    <image url="Flower Photo 3.jpg" />
    <image url="Flower Photo 4.jpg" />
    <image url="Flower Photo 5.jpg" />
    <image url="Flower Photo 6.jpg" />
    <image url="Flower Photo 7.jpg" />
    <image url="Flower Photo 8.jpg" />
    <image url="Flower Photo 9.jpg" />
    <image url="Flower Photo 10.jpg" />
    <image url="Flower Photo 11.jpg" />
    </gallery>

    -> PHP type

    <?php
    $xml = simplexml_load_file("ImageGallery.xml");

    echo $xml->getName() . "<br />";

    foreach($xml->children() as $child)
    {
    echo $child->getName() . ": " . $child . "<br />";
    }
    ?>
     

    ChuttaFX

    Member
    Nov 15, 2008
    4,587
    12
    0
    macho meka wadada kiyala balanna. wada nam kiyanna :D

    PHP:
    <?php
    $filename = 'file_name_eka.xml';
    $handle = fopen($filename, 'r');
    $contents = fread($handle, filesize($filename));
    fclose($handle);
    $count = strlen($contents)-strlen('</gallery>');
    $fileread = substr($contents,0,$count);
    $imagename = 'image_eke_name_eka.jpg';
    $handle = fopen($filename, 'w');
    $fileprint = $fileread.'<image url="'.$imagename.'">   </gallery>';
    fwrite($handle,$fileprint);
    fclose($handle);
    ?>


    PS: meeta wada hoda krama thiyanawa xml file edit karanna. but mama danne na.
     
    Last edited: