Someone to help with simple modification of php code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nsr500rossi
Forum Newbie
Posts: 1
Joined: Thu Jan 17, 2008 3:09 pm

Someone to help with simple modification of php code

Post by nsr500rossi »

Hi all
I have an editxml.php file that takes this code:

Code: Select all

<img src="RLW_001.jpg" title="Please click on photograph to purhase" caption="RLW_001.jpg" link="" />
and when run, turns it into this code:

Code: Select all

<img src="BST 001.jpg" title="Please click on photograph to purchase" caption="BST 001.jpg" link="javascript&#058;NewWindow=window.open('/Payment_page2.php?name=BST 001.jpg&album=Brighton speed trials 2006','myWindow','width=300,height=660,toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes');NewWindow.focus(); void(0);" />
I need to change the editxml.php so that it creates a xml file like this

Code: Select all

<img src="ECO_007.jpg" title="Please click on Photograph to purchase" caption="ECO_007.jpg" link="http://www.michaelshuttleworth.com/Payment_page2.php?name=ECO_007.jpg&album=Ecofair_2006" target="_self" />
Ignore the filenames (i have taken them from different sources)

Here is the editxml.php code that needs changing:

Code: Select all

<html>
<head>
  <title>PHP Test</title>
</head>
<body>
 
 
<?php 
 
$file = "images.xml"; 
$descriptor = fopen ($file, "r");
$contents = fread($descriptor , filesize($file));
$album = '';
 
$pos1 = strpos($contents, 'javascript&#058;NewWindow');
if ($pos1 == false) {
 
    $pieces = explode('link=""', $contents);
    $op = "";
 
    for ($i = 0; $i < count($pieces); $i++) {
 
        $tnpos = strpos($pieces[$i], 'tnPath="');
        if ($tnpos !== false)
        {
            $titpos = strpos($pieces[$i], 'ssp_director/albums/', $tnpos);
            $titpos += 20;
            $titend = strpos($pieces[$i], '/', $titpos) - $titpos;
            $album = substr($pieces[$i], $titpos, $titend);
//echo $album;
        }
 
        $halves = explode('<img src="', $pieces[$i]);
        $fileid = substr($halves[1], 0, 7);
        if (count($halves) > 1) {
            $halves[0] .= '<img src="';
 
            $pos1 = strpos($halves[1], 'unavailable');
            if ($pos1 == false) {
                $halves[1] .= "link=\"javascript&#058;NewWindow=window.open('/Payment_page.php?name=" . $fileid . ".jpg&album=" . $album . "','myWindow','width=300,height=730,toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes');NewWindow.focus(); void(0);\""; 
            } else {
                $halves[1] .= 'link=""';
            }
        }
        $op .= $halves[0] . $halves[1];
    }
 
    fclose($descriptor);
    unlink($file);
//$descriptor = fopen ('images.txt', "w"); 
    $descriptor = fopen ($file, "w"); 
    fwrite($descriptor,$op);
 
    echo 'done! '; 
    echo count($pieces);
    echo ' pieces processed';
 
    fclose($descriptor);
 
} else {
    echo 'This file has been processed already';
}
 
?>
 
</body>
</html> 
I guess the javascript newwindow code needs replacing, i have tried but can't quite get it right.

If anyone out there can show me what to change i would be so so grateful.

Many thanks

Mike
Post Reply