ExportLatex.class.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Set of methods used to build dumps of tables as Latex
  5. *
  6. * @package PhpMyAdmin-Export
  7. * @subpackage Latex
  8. */
  9. if (! defined('PHPMYADMIN')) {
  10. exit;
  11. }
  12. /* Get the export interface */
  13. require_once 'libraries/plugins/ExportPlugin.class.php';
  14. /**
  15. * Handles the export for the Latex format
  16. *
  17. * @package PhpMyAdmin-Export
  18. * @subpackage Latex
  19. */
  20. class ExportLatex extends ExportPlugin
  21. {
  22. /**
  23. * Constructor
  24. */
  25. public function __construct()
  26. {
  27. // initialize the specific export sql variables
  28. $this->initSpecificVariables();
  29. $this->setProperties();
  30. }
  31. /**
  32. * Initialize the local variables that are used for export Latex
  33. *
  34. * @return void
  35. */
  36. protected function initSpecificVariables()
  37. {
  38. /* Messages used in default captions */
  39. $GLOBALS['strLatexContent'] = __('Content of table @TABLE@');
  40. $GLOBALS['strLatexContinued'] = __('(continued)');
  41. $GLOBALS['strLatexStructure'] = __('Structure of table @TABLE@');
  42. }
  43. /**
  44. * Sets the export Latex properties
  45. *
  46. * @return void
  47. */
  48. protected function setProperties()
  49. {
  50. global $plugin_param;
  51. $hide_structure = false;
  52. if ($plugin_param['export_type'] == 'table'
  53. && ! $plugin_param['single_table']
  54. ) {
  55. $hide_structure = true;
  56. }
  57. $props = 'libraries/properties/';
  58. include_once "$props/plugins/ExportPluginProperties.class.php";
  59. include_once "$props/options/groups/OptionsPropertyRootGroup.class.php";
  60. include_once "$props/options/groups/OptionsPropertyMainGroup.class.php";
  61. include_once "$props/options/items/BoolPropertyItem.class.php";
  62. include_once "$props/options/items/RadioPropertyItem.class.php";
  63. include_once "$props/options/items/TextPropertyItem.class.php";
  64. $exportPluginProperties = new ExportPluginProperties();
  65. $exportPluginProperties->setText('LaTeX');
  66. $exportPluginProperties->setExtension('tex');
  67. $exportPluginProperties->setMimeType('application/x-tex');
  68. $exportPluginProperties->setOptionsText(__('Options'));
  69. // create the root group that will be the options field for
  70. // $exportPluginProperties
  71. // this will be shown as "Format specific options"
  72. $exportSpecificOptions = new OptionsPropertyRootGroup();
  73. $exportSpecificOptions->setName("Format Specific Options");
  74. // general options main group
  75. $generalOptions = new OptionsPropertyMainGroup();
  76. $generalOptions->setName("general_opts");
  77. // create primary items and add them to the group
  78. $leaf = new BoolPropertyItem();
  79. $leaf->setName("caption");
  80. $leaf->setText(__('Include table caption'));
  81. $generalOptions->addProperty($leaf);
  82. // add the main group to the root group
  83. $exportSpecificOptions->addProperty($generalOptions);
  84. // what to dump (structure/data/both) main group
  85. $dumpWhat = new OptionsPropertyMainGroup();
  86. $dumpWhat->setName("dump_what");
  87. $dumpWhat->setText(__('Dump table'));
  88. // create primary items and add them to the group
  89. $leaf = new RadioPropertyItem();
  90. $leaf->setName("structure_or_data");
  91. $leaf->setValues(
  92. array(
  93. 'structure' => __('structure'),
  94. 'data' => __('data'),
  95. 'structure_and_data' => __('structure and data')
  96. )
  97. );
  98. $dumpWhat->addProperty($leaf);
  99. // add the main group to the root group
  100. $exportSpecificOptions->addProperty($dumpWhat);
  101. // structure options main group
  102. if (! $hide_structure) {
  103. $structureOptions = new OptionsPropertyMainGroup();
  104. $structureOptions->setName("structure");
  105. $structureOptions->setText(__('Object creation options'));
  106. $structureOptions->setForce('data');
  107. // create primary items and add them to the group
  108. $leaf = new TextPropertyItem();
  109. $leaf->setName("structure_caption");
  110. $leaf->setText(__('Table caption:'));
  111. $leaf->setDoc('faq6-27');
  112. $structureOptions->addProperty($leaf);
  113. $leaf = new TextPropertyItem();
  114. $leaf->setName("structure_continued_caption");
  115. $leaf->setText(__('Table caption (continued):'));
  116. $leaf->setDoc('faq6-27');
  117. $structureOptions->addProperty($leaf);
  118. $leaf = new TextPropertyItem();
  119. $leaf->setName("structure_label");
  120. $leaf->setText(__('Label key:'));
  121. $leaf->setDoc('faq6-27');
  122. $structureOptions->addProperty($leaf);
  123. if (! empty($GLOBALS['cfgRelation']['relation'])) {
  124. $leaf = new BoolPropertyItem();
  125. $leaf->setName("relation");
  126. $leaf->setText(__('Display foreign key relationships'));
  127. $structureOptions->addProperty($leaf);
  128. }
  129. $leaf = new BoolPropertyItem();
  130. $leaf->setName("comments");
  131. $leaf->setText(__('Display comments'));
  132. $structureOptions->addProperty($leaf);
  133. if (! empty($GLOBALS['cfgRelation']['mimework'])) {
  134. $leaf = new BoolPropertyItem();
  135. $leaf->setName("mime");
  136. $leaf->setText(__('Display MIME types'));
  137. $structureOptions->addProperty($leaf);
  138. }
  139. // add the main group to the root group
  140. $exportSpecificOptions->addProperty($structureOptions);
  141. }
  142. // data options main group
  143. $dataOptions = new OptionsPropertyMainGroup();
  144. $dataOptions->setName("data");
  145. $dataOptions->setText(__('Data dump options'));
  146. $dataOptions->setForce('structure');
  147. // create primary items and add them to the group
  148. $leaf = new BoolPropertyItem();
  149. $leaf->setName("columns");
  150. $leaf->setText(__('Put columns names in the first row:'));
  151. $dataOptions->addProperty($leaf);
  152. $leaf = new TextPropertyItem();
  153. $leaf->setName("data_caption");
  154. $leaf->setText(__('Table caption:'));
  155. $leaf->setDoc('faq6-27');
  156. $dataOptions->addProperty($leaf);
  157. $leaf = new TextPropertyItem();
  158. $leaf->setName("data_continued_caption");
  159. $leaf->setText(__('Table caption (continued):'));
  160. $leaf->setDoc('faq6-27');
  161. $dataOptions->addProperty($leaf);
  162. $leaf = new TextPropertyItem();
  163. $leaf->setName("data_label");
  164. $leaf->setText(__('Label key:'));
  165. $leaf->setDoc('faq6-27');
  166. $dataOptions->addProperty($leaf);
  167. $leaf = new TextPropertyItem();
  168. $leaf->setName('null');
  169. $leaf->setText(__('Replace NULL with:'));
  170. $dataOptions->addProperty($leaf);
  171. // add the main group to the root group
  172. $exportSpecificOptions->addProperty($dataOptions);
  173. // set the options for the export plugin property item
  174. $exportPluginProperties->setOptions($exportSpecificOptions);
  175. $this->properties = $exportPluginProperties;
  176. }
  177. /**
  178. * This method is called when any PluginManager to which the observer
  179. * is attached calls PluginManager::notify()
  180. *
  181. * @param SplSubject $subject The PluginManager notifying the observer
  182. * of an update.
  183. *
  184. * @return void
  185. */
  186. public function update (SplSubject $subject)
  187. {
  188. }
  189. /**
  190. * Outputs export header
  191. *
  192. * @return bool Whether it succeeded
  193. */
  194. public function exportHeader ()
  195. {
  196. global $crlf;
  197. global $cfg;
  198. $head = '% phpMyAdmin LaTeX Dump' . $crlf
  199. . '% version ' . PMA_VERSION . $crlf
  200. . '% http://www.phpmyadmin.net' . $crlf
  201. . '%' . $crlf
  202. . '% ' . __('Host:') . ' ' . $cfg['Server']['host'];
  203. if (! empty($cfg['Server']['port'])) {
  204. $head .= ':' . $cfg['Server']['port'];
  205. }
  206. $head .= $crlf
  207. . '% ' . __('Generation Time:') . ' '
  208. . PMA_Util::localisedDate() . $crlf
  209. . '% ' . __('Server version:') . ' ' . PMA_MYSQL_STR_VERSION . $crlf
  210. . '% ' . __('PHP Version:') . ' ' . phpversion() . $crlf;
  211. return PMA_exportOutputHandler($head);
  212. }
  213. /**
  214. * Outputs export footer
  215. *
  216. * @return bool Whether it succeeded
  217. */
  218. public function exportFooter ()
  219. {
  220. return true;
  221. }
  222. /**
  223. * Outputs database header
  224. *
  225. * @param string $db Database name
  226. *
  227. * @return bool Whether it succeeded
  228. */
  229. public function exportDBHeader ($db)
  230. {
  231. global $crlf;
  232. $head = '% ' . $crlf
  233. . '% ' . __('Database:') . ' ' . '\'' . $db . '\'' . $crlf
  234. . '% ' . $crlf;
  235. return PMA_exportOutputHandler($head);
  236. }
  237. /**
  238. * Outputs database footer
  239. *
  240. * @param string $db Database name
  241. *
  242. * @return bool Whether it succeeded
  243. */
  244. public function exportDBFooter ($db)
  245. {
  246. return true;
  247. }
  248. /**
  249. * Outputs CREATE DATABASE statement
  250. *
  251. * @param string $db Database name
  252. *
  253. * @return bool Whether it succeeded
  254. */
  255. public function exportDBCreate($db)
  256. {
  257. return true;
  258. }
  259. /**
  260. * Outputs the content of a table in JSON format
  261. *
  262. * @param string $db database name
  263. * @param string $table table name
  264. * @param string $crlf the end of line sequence
  265. * @param string $error_url the url to go back in case of error
  266. * @param string $sql_query SQL query for obtaining data
  267. *
  268. * @return bool Whether it succeeded
  269. */
  270. public function exportData($db, $table, $crlf, $error_url, $sql_query)
  271. {
  272. $result = $GLOBALS['dbi']->tryQuery(
  273. $sql_query, null, PMA_DatabaseInterface::QUERY_UNBUFFERED
  274. );
  275. $columns_cnt = $GLOBALS['dbi']->numFields($result);
  276. $columns = array();
  277. for ($i = 0; $i < $columns_cnt; $i++) {
  278. $columns[$i] = $GLOBALS['dbi']->fieldName($result, $i);
  279. }
  280. unset($i);
  281. $buffer = $crlf . '%' . $crlf . '% ' . __('Data:') . ' ' . $table
  282. . $crlf . '%' . $crlf . ' \\begin{longtable}{|';
  283. for ($index = 0; $index < $columns_cnt; $index++) {
  284. $buffer .= 'l|';
  285. }
  286. $buffer .= '} ' . $crlf ;
  287. $buffer .= ' \\hline \\endhead \\hline \\endfoot \\hline ' . $crlf;
  288. if (isset($GLOBALS['latex_caption'])) {
  289. $buffer .= ' \\caption{'
  290. . PMA_Util::expandUserString(
  291. $GLOBALS['latex_data_caption'],
  292. array(
  293. 'texEscape',
  294. get_class($this),
  295. 'libraries/plugins/export/' . get_class($this) . ".class.php"
  296. ),
  297. array('table' => $table, 'database' => $db)
  298. )
  299. . '} \\label{'
  300. . PMA_Util::expandUserString(
  301. $GLOBALS['latex_data_label'],
  302. null,
  303. array('table' => $table, 'database' => $db)
  304. )
  305. . '} \\\\';
  306. }
  307. if (! PMA_exportOutputHandler($buffer)) {
  308. return false;
  309. }
  310. // show column names
  311. if (isset($GLOBALS['latex_columns'])) {
  312. $buffer = '\\hline ';
  313. for ($i = 0; $i < $columns_cnt; $i++) {
  314. $buffer .= '\\multicolumn{1}{|c|}{\\textbf{'
  315. . self::texEscape(stripslashes($columns[$i])) . '}} & ';
  316. }
  317. $buffer = substr($buffer, 0, -2) . '\\\\ \\hline \hline ';
  318. if (! PMA_exportOutputHandler($buffer . ' \\endfirsthead ' . $crlf)) {
  319. return false;
  320. }
  321. if (isset($GLOBALS['latex_caption'])) {
  322. if (! PMA_exportOutputHandler(
  323. '\\caption{'
  324. . PMA_Util::expandUserString(
  325. $GLOBALS['latex_data_continued_caption'],
  326. array(
  327. 'texEscape',
  328. get_class($this),
  329. 'libraries/plugins/export/'
  330. . get_class($this) . ".class.php"
  331. ),
  332. array('table' => $table, 'database' => $db)
  333. )
  334. . '} \\\\ '
  335. )) {
  336. return false;
  337. }
  338. }
  339. if (! PMA_exportOutputHandler($buffer . '\\endhead \\endfoot' . $crlf)) {
  340. return false;
  341. }
  342. } else {
  343. if (! PMA_exportOutputHandler('\\\\ \hline')) {
  344. return false;
  345. }
  346. }
  347. // print the whole table
  348. while ($record = $GLOBALS['dbi']->fetchAssoc($result)) {
  349. $buffer = '';
  350. // print each row
  351. for ($i = 0; $i < $columns_cnt; $i++) {
  352. if ((! function_exists('is_null')
  353. || ! is_null($record[$columns[$i]]))
  354. && isset($record[$columns[$i]])
  355. ) {
  356. $column_value = self::texEscape(
  357. stripslashes($record[$columns[$i]])
  358. );
  359. } else {
  360. $column_value = $GLOBALS['latex_null'];
  361. }
  362. // last column ... no need for & character
  363. if ($i == ($columns_cnt - 1)) {
  364. $buffer .= $column_value;
  365. } else {
  366. $buffer .= $column_value . " & ";
  367. }
  368. }
  369. $buffer .= ' \\\\ \\hline ' . $crlf;
  370. if (! PMA_exportOutputHandler($buffer)) {
  371. return false;
  372. }
  373. }
  374. $buffer = ' \\end{longtable}' . $crlf;
  375. if (! PMA_exportOutputHandler($buffer)) {
  376. return false;
  377. }
  378. $GLOBALS['dbi']->freeResult($result);
  379. return true;
  380. } // end getTableLaTeX
  381. /**
  382. * Outputs table's structure
  383. *
  384. * @param string $db database name
  385. * @param string $table table name
  386. * @param string $crlf the end of line sequence
  387. * @param string $error_url the url to go back in case of error
  388. * @param string $export_mode 'create_table', 'triggers', 'create_view',
  389. * 'stand_in'
  390. * @param string $export_type 'server', 'database', 'table'
  391. * @param bool $do_relation whether to include relation comments
  392. * @param bool $do_comments whether to include the pmadb-style column
  393. * comments as comments in the structure;
  394. * this is deprecated but the parameter is
  395. * left here because export.php calls
  396. * exportStructure() also for other
  397. * export types which use this parameter
  398. * @param bool $do_mime whether to include mime comments
  399. * @param bool $dates whether to include creation/update/check dates
  400. *
  401. * @return bool Whether it succeeded
  402. */
  403. public function exportStructure(
  404. $db,
  405. $table,
  406. $crlf,
  407. $error_url,
  408. $export_mode,
  409. $export_type,
  410. $do_relation = false,
  411. $do_comments = false,
  412. $do_mime = false,
  413. $dates = false
  414. ) {
  415. global $cfgRelation;
  416. /* We do not export triggers */
  417. if ($export_mode == 'triggers') {
  418. return true;
  419. }
  420. /**
  421. * Get the unique keys in the table
  422. */
  423. $unique_keys = array();
  424. $keys = $GLOBALS['dbi']->getTableIndexes($db, $table);
  425. foreach ($keys as $key) {
  426. if ($key['Non_unique'] == 0) {
  427. $unique_keys[] = $key['Column_name'];
  428. }
  429. }
  430. /**
  431. * Gets fields properties
  432. */
  433. $GLOBALS['dbi']->selectDb($db);
  434. // Check if we can use Relations
  435. if ($do_relation && ! empty($cfgRelation['relation'])) {
  436. // Find which tables are related with the current one and write it in
  437. // an array
  438. $res_rel = PMA_getForeigners($db, $table);
  439. if ($res_rel && count($res_rel) > 0) {
  440. $have_rel = true;
  441. } else {
  442. $have_rel = false;
  443. }
  444. } else {
  445. $have_rel = false;
  446. } // end if
  447. /**
  448. * Displays the table structure
  449. */
  450. $buffer = $crlf . '%' . $crlf . '% ' . __('Structure:') . ' ' . $table
  451. . $crlf . '%' . $crlf . ' \\begin{longtable}{';
  452. if (! PMA_exportOutputHandler($buffer)) {
  453. return false;
  454. }
  455. $columns_cnt = 4;
  456. $alignment = '|l|c|c|c|';
  457. if ($do_relation && $have_rel) {
  458. $columns_cnt++;
  459. $alignment .= 'l|';
  460. }
  461. if ($do_comments) {
  462. $columns_cnt++;
  463. $alignment .= 'l|';
  464. }
  465. if ($do_mime && $cfgRelation['mimework']) {
  466. $columns_cnt++;
  467. $alignment .='l|';
  468. }
  469. $buffer = $alignment . '} ' . $crlf ;
  470. $header = ' \\hline ';
  471. $header .= '\\multicolumn{1}{|c|}{\\textbf{' . __('Column')
  472. . '}} & \\multicolumn{1}{|c|}{\\textbf{' . __('Type')
  473. . '}} & \\multicolumn{1}{|c|}{\\textbf{' . __('Null')
  474. . '}} & \\multicolumn{1}{|c|}{\\textbf{' . __('Default') . '}}';
  475. if ($do_relation && $have_rel) {
  476. $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . __('Links to') . '}}';
  477. }
  478. if ($do_comments) {
  479. $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . __('Comments') . '}}';
  480. $comments = PMA_getComments($db, $table);
  481. }
  482. if ($do_mime && $cfgRelation['mimework']) {
  483. $header .= ' & \\multicolumn{1}{|c|}{\\textbf{MIME}}';
  484. $mime_map = PMA_getMIME($db, $table, true);
  485. }
  486. // Table caption for first page and label
  487. if (isset($GLOBALS['latex_caption'])) {
  488. $buffer .= ' \\caption{'
  489. . PMA_Util::expandUserString(
  490. $GLOBALS['latex_structure_caption'],
  491. array(
  492. 'texEscape',
  493. get_class($this),
  494. 'libraries/plugins/export/' . get_class($this) . ".class.php"
  495. ),
  496. array('table' => $table, 'database' => $db)
  497. )
  498. . '} \\label{'
  499. . PMA_Util::expandUserString(
  500. $GLOBALS['latex_structure_label'],
  501. null,
  502. array('table' => $table, 'database' => $db)
  503. )
  504. . '} \\\\' . $crlf;
  505. }
  506. $buffer .= $header . ' \\\\ \\hline \\hline' . $crlf
  507. . '\\endfirsthead' . $crlf;
  508. // Table caption on next pages
  509. if (isset($GLOBALS['latex_caption'])) {
  510. $buffer .= ' \\caption{'
  511. . PMA_Util::expandUserString(
  512. $GLOBALS['latex_structure_continued_caption'],
  513. array(
  514. 'texEscape',
  515. get_class($this),
  516. 'libraries/plugins/export/' . get_class($this) . ".class.php"
  517. ),
  518. array('table' => $table, 'database' => $db)
  519. )
  520. . '} \\\\ ' . $crlf;
  521. }
  522. $buffer .= $header . ' \\\\ \\hline \\hline \\endhead \\endfoot ' . $crlf;
  523. if (! PMA_exportOutputHandler($buffer)) {
  524. return false;
  525. }
  526. $fields = $GLOBALS['dbi']->getColumns($db, $table);
  527. foreach ($fields as $row) {
  528. $extracted_columnspec
  529. = PMA_Util::extractColumnSpec(
  530. $row['Type']
  531. );
  532. $type = $extracted_columnspec['print_type'];
  533. if (empty($type)) {
  534. $type = ' ';
  535. }
  536. if (! isset($row['Default'])) {
  537. if ($row['Null'] != 'NO') {
  538. $row['Default'] = 'NULL';
  539. }
  540. }
  541. $field_name = $row['Field'];
  542. $local_buffer = $field_name . "\000" . $type . "\000"
  543. . (($row['Null'] == '' || $row['Null'] == 'NO')
  544. ? __('No') : __('Yes'))
  545. . "\000" . (isset($row['Default']) ? $row['Default'] : '');
  546. if ($do_relation && $have_rel) {
  547. $local_buffer .= "\000";
  548. if (isset($res_rel[$field_name])) {
  549. $local_buffer .= $res_rel[$field_name]['foreign_table'] . ' ('
  550. . $res_rel[$field_name]['foreign_field'] . ')';
  551. }
  552. }
  553. if ($do_comments && $cfgRelation['commwork']) {
  554. $local_buffer .= "\000";
  555. if (isset($comments[$field_name])) {
  556. $local_buffer .= $comments[$field_name];
  557. }
  558. }
  559. if ($do_mime && $cfgRelation['mimework']) {
  560. $local_buffer .= "\000";
  561. if (isset($mime_map[$field_name])) {
  562. $local_buffer .= str_replace(
  563. '_',
  564. '/',
  565. $mime_map[$field_name]['mimetype']
  566. );
  567. }
  568. }
  569. $local_buffer = self::texEscape($local_buffer);
  570. if ($row['Key']=='PRI') {
  571. $pos=strpos($local_buffer, "\000");
  572. $local_buffer = '\\textit{'
  573. . substr($local_buffer, 0, $pos)
  574. . '}' . substr($local_buffer, $pos);
  575. }
  576. if (in_array($field_name, $unique_keys)) {
  577. $pos=strpos($local_buffer, "\000");
  578. $local_buffer = '\\textbf{'
  579. . substr($local_buffer, 0, $pos)
  580. . '}' . substr($local_buffer, $pos);
  581. }
  582. $buffer = str_replace("\000", ' & ', $local_buffer);
  583. $buffer .= ' \\\\ \\hline ' . $crlf;
  584. if (! PMA_exportOutputHandler($buffer)) {
  585. return false;
  586. }
  587. } // end while
  588. $buffer = ' \\end{longtable}' . $crlf;
  589. return PMA_exportOutputHandler($buffer);
  590. } // end of the 'exportStructure' method
  591. /**
  592. * Escapes some special characters for use in TeX/LaTeX
  593. *
  594. * @param string $string the string to convert
  595. *
  596. * @return string the converted string with escape codes
  597. */
  598. public static function texEscape($string)
  599. {
  600. $escape = array('$', '%', '{', '}', '&', '#', '_', '^');
  601. $cnt_escape = count($escape);
  602. for ($k = 0; $k < $cnt_escape; $k++) {
  603. $string = str_replace($escape[$k], '\\' . $escape[$k], $string);
  604. }
  605. return $string;
  606. }
  607. }
  608. ?>