Code: Select all
$marctemplate = <<<EOD
=LDR 00000nam 2200000Ia 4500
=008 YYMMDD?DAT1\\\\CNT\\\\\\\\\\\000\0\LNG\d
=020 \$a{ISBN} :\$c{PRICE}
=100 1\$a{AUTHOR_SURNAME, AUTHOR_FIRST_NAME}
=245 10\$a{BOOK}/\$c{AUTHOR}
=250 \$a{EDITION}
=260 \$a{PUBLISHERADD} : \$b{PUBLISHER},\$c{DATED}
=300 \$a\{PAGENO} ; \$c{SIZE}
=500 \$a{REMARKS}
=653 1\$a{SUBJECT}
=852 41\$aMadan Puraskar Pustakalaya\$ePatanDhoka Lalitpur,Nepal\$j{SN}
EOD;
In this template, $a,$b,$c are not actually a variable but are the mark standard which should not be replaced. Only the string constant in uppercase within the curly braces must be replaced.
A modified code is given below. Hoping to get your suggestions soon.
Code: Select all
<?php
header('Content-Type: text/html; charset=utf-8');
include("db.php");
//ini_set("default_charset", "utf-8");
$connection = sql_db_connect(HOST, USER, PASS, DB, PORT);
$sql = "select * from tblmpp";
$rs = mysql_query($sql) or die(mysql_error());
$x = 1;
while($row = mysql_fetch_array($rs)){
$sn = $row['sn'];
$book = $row['book'];
print $book."\n";
$author = $row['author'];
$author_array = explode(" ", $author);
$author_fname = $author_array[0];
unset($author_array[0]);
$author_lname = implode(" ", $author_array);
$publisher = $row['publisher'];
$publisheradd = $row['publisheradd'];
$price = $row['price'];
$isbn = $row['isbn'];
$subject = $row['subject'];
$remarks = $row['remarks'];
$pageno = $row['pageno'];
$size = $row['size'];
$dated = $row['dated'];
$edition = $row['edition'];
$file_name = $x.".mrk";
$hnd = fopen($file_name, "w+");
include("marc.tpl");
$marctemplate = "\xEF\xBB\xBF".$marctemplate;
$marctemplate = str_replace('{SN}', $sn, $marctemplate);
$marctemplate = str_replace('{BOOK}', $book, $marctemplate);
$marctemplate = str_replace('{AUTHOR}', $author, $marctemplate);
$marctemplate = str_replace('{AUTHOR}', $author, $marctemplate);
$marctemplate = str_replace('AUTHOR_SURNAME', $author_lname, $marctemplate);
$marctemplate = str_replace('AUTHOR_FIRST_NAME', $author_fname, $marctemplate);
$marctemplate = str_replace('{PUBLISHER}', $publisher, $marctemplate);
$marctemplate = str_replace('{PUBLISHERADD}', $publisheradd, $marctemplate);
$marctemplate = str_replace('{PRICE}', $price, $marctemplate);
$marctemplate = str_replace('{ISBN}', $isbn, $marctemplate);
$marctemplate = str_replace('{REMARKS}', $remarks, $marctemplate);
$marctemplate = str_replace('{DATED}', $dated, $marctemplate);
$marctemplate = str_replace('{EDITION}', $edition, $marctemplate);
$marctemplate = str_replace('{SUBJECT}', $subject, $marctemplate);
$marctemplate = str_replace('{PAGENO}', $pageno, $marctemplate);
$marctemplate = str_replace('{SIZE}', $size, $marctemplate);
file_put_contents($file_name, $marctemplate);
$x++;
fclose($hnd);
}
?>