Hi all.
In my code I am reading strings from a JS array which is found in a file.
Some of the strings have esacped single-quotes in them, for example: "New Year's Eve".
In my code, I am reading them, then printing them out to an HTML form.
When the form is submitted I am retrieving them back by POST, and then writing the file again.
However, when I load the file the next time, what I get is "New Year\" and that's it.
What could cause that?
[Solved] Backslashing problem
Moderator: General Moderators
[Solved] Backslashing problem
Last edited by pilau on Fri Sep 30, 2005 3:12 am, edited 1 time in total.
Magic quotes are off, but it's not working.
Here's the code the reads the file and prints the page:
The summon for that is as follows: print_page(read_contents));
The code that writes to the file:
Maybe you could tell what's wrong?
Here's the code the reads the file and prints the page:
Code: Select all
function read_contents() {
$events_script = file_get_contents("events.script");
$file = preg_split("/events\[[0-9]{1,2}\]=\{/", $events_script);
array_shift($file);
return $file;
} // read end
function print_page($months) {
//Begin Master array interpretation
while (list($var, $val) = each($months)) {
preg_match_all("#^\s*(\d+):\"(.*?)\".*$#m", $months[$var], $events);
array_shift($events);
print " <tr bgcolor=\"#FFCC00\">
<td colspan=\"2\">
<input type=\"checkbox\" onClick=\"getStatus('".return_month_name($var)."')\" checked>
" . return_month_name($var) . " <font size=\"1\">(Uncheck to remove events)</font>
</td>
</tr>
";
//Begin Secondary array interpretation
$events = array_combine_emulated($events[0],$events[1]);
$i = 0;
while (list($event_key, $event_val) = each($events)) {
$i++;
print " <tr>
<td bgcolor='#FF9900' width='10'>
<input type='checkbox' name='".return_month_name($var)."[row".$i."][checkbox]' value='".$event_key."' onClick=\"checkBox('".return_month_name($var)."',".$i.")\" checked>
<input type='hidden' name='".return_month_name($var)."[row".$i."][present]' value='true'>
</td>
<td bgcolor='#FFFFCC' width='530' colspan='2'>
<input type='text' name='".return_month_name($var)."[row".$i."][day]' size='1' value='{$event_key}'>
<input type='text' name='".return_month_name($var)."[row".$i."][eventname]' size='50' value='".stripslashes($event_val)."'>
</td>
</tr>
";
} //Secondary
} //Master
} // print function endThe code that writes to the file:
Code: Select all
function write_contents() {
$JSarray = "";
$JSarray = "events={}\n";
for($j=0; $j < 12; ++$j)
{
$JSarray .= "events[{$j}]={\n";
while(list($rowindex,$rowarray) = each($_POST[''.return_month_name($j).''])) {
if ($rowindex != "row1") {
$JSarray .= ",\n";
} //endif
if ($rowarray['present'] == "true") {
$JSarray .= " ".$rowarray['day'].":\"".addslashes($rowarray['eventname'])."\"";
} //endif
} //endwhile
if ($_POST['action'] == "addfields" && $_POST['monthadd'] == return_month_name($j))
{
for($i=($rowarray['day']+1); $i <= $_POST['nof']; $i++)
{
$JSarray .= " ".$i.":\"Enter event here\"";
} //endfor
} //endif
$JSarray .= " }\n";
} //endfor
file_put_contents("events.script",$JSarray);
} // write_contents end