Computing.Net > Forums > Web Development > PHP quotation mark escape, part 2

PHP quotation mark escape, part 2

Reply to Message Icon

Original Message
Name: Spinal
Date: January 24, 2005 at 14:05:56 Pacific
Subject: PHP quotation mark escape, part 2
OS: W2K, W3.1, WBob
CPU/Ram: 384Mb, 2Mb, 2Mb
Comment:

Hello again, I had asked for info on quotation mark escapes and got told to use htmlentity(), but alas that makes no difference. Copied below are my two source codes... can anyone help?


#!/usr/bin/php
<html>
<title>Modifica Articolo </title>
<body>

<table border="cellspacing="5" cellpadding="1">
<tr>
<td width=100% valign = TOP>
Modifica:
<?php

$fname = "files/" . $_POST["mfilename"];
echo $fname."

";

//read and print file contents
echo "--ORIGINALE--
<hr>";

$data = file_get_contents($fname) or die ("Could not read file!");


echo $data;
echo "<hr>

";
$data = unhtmlentities($data);
function unhtmlentities($string)
{
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);
return strtr($string, $trans_tbl);
}


echo "--MODIFICA--
(accetta html)
";
// now to output the form HTML.
echo "<form method=\"post\" action=\"salva.php\">";
echo "<table border=\"cellspacing=\"5\" cellpadding=\"1\">";

echo "<td><TEXTAREA NAME=\"data\" ROWS=40 COLS=120>$data</TEXTAREA></td>

";
echo "<input type=\"hidden\" name=\"fname\" value=\"$fname\">";

echo "<tr><td colspan=\"2\"><input type=\"submit\" value=\"Salva\" name=\"submit\">
<input type=\"reset\" value=\"Cancella Modifiche\" name=\"reset\">
</td>
</tr>";

echo "</table></form>";


?>


</td>
<td>
<? include "tags.html"?>
</td>

</tr>
</table>

<hr>


</body>
</html>


Report Offensive Message For Removal


Response Number 1
Name: Spinal
Date: January 24, 2005 at 14:07:03 Pacific
Subject: PHP quotation mark escape, part 2
Reply: (edit)

---salva.php---

#!/usr/bin/php
<html>
<head>
<title>Salva Articolo</title>
<meta http-equiv="REFRESH" content="10; URL=admin.php">
</head>

<body>

<?php

// get data from post
$data = $_POST["data"];
$data = htmlentities($data);
$dest = $_POST["fname"];


// write destination
$fp = fopen ("$dest", "w") or die("Non ho potuto aprire il file richiesto");
fwrite($fp, $data) or die("Non ho potuto scrivere il file richiesto!") ;
fclose($fp) or die ("Non ho potuto chiudere il file richiesto!");

// too new version, not supported apaprently
//file_put_contents($dest, $data) or die("Non ho potuto scrivere il file richiesto!");

// print confirmation
echo "File salvato, trasferimento automatico in 10 secondi

";
echo " Oppure clicca qua per tornare subito";

?>

</body>
</html>


Report Offensive Follow Up For Removal

Response Number 2
Name: Laler
Date: January 24, 2005 at 15:16:36 Pacific
Subject: PHP quotation mark escape, part 2
Reply: (edit)

how about stripslashes() ?

^o^
are you in Asia? do you watch Animax Asia? Please Vote


Report Offensive Follow Up For Removal

Response Number 3
Name: Laler
Date: January 24, 2005 at 15:29:01 Pacific
Subject: PHP quotation mark escape, part 2
Reply: (edit)

htmlentity is useful to convert all characters to its HTML code equivalent (if it have one).

htmlspecialchars is similar, but only convert a few critical chars.

stripslashes() , judging by its name is used to strip the slashes (if any) out of characters that requires escaping. complete explanation on the page above :P

^o^
are you in Asia? do you watch Animax Asia? Please Vote


Report Offensive Follow Up For Removal

Response Number 4
Name: Spinal
Date: January 26, 2005 at 10:00:50 Pacific
Subject: PHP quotation mark escape, part 2
Reply: (edit)

Thanks, I think I can fiddle with stripslashes :D


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: PHP quotation mark escape, part 2

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge