6 Replies - 2108 Views - Last Post: 03 October 2006 - 05:01 PM Rate Topic: -----

#1 BetaWar   User is offline

  • #include "soul.h"
  • member icon

Reputation: 1651
  • View blog
  • Posts: 8,523
  • Joined: 07-September 06

How do I get rid of the \s

Posted 01 October 2006 - 09:45 PM

Okay well I have created a file manager that works. But when I edit a .php file and it has quotes (single and double) it adds a back-slash '\' before the open, and before the end quote which causes an error to popup when attempting to load the page.

Here is what the code looks like:

<?php

if(!isset($_SESSION[loggedin])){
echo'Error.';
}
else{

?>
<td width="150px" valign="top">
<a href="?act=home2b">
Home
</a>
<br>
<a href="?act=delete2">
Delete File
</a>
<br>
<a href="?act=edit2">
Edit File
</a>
<br>
<a href="?act=new2">
New File
</a>
<br>
</td>
<td width="640px" valign="top">
<?

$code=$_POST[code];
$edit=$_GET[edit];

if(isset($edit) && isset($code)){

$myFile = $edit;
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $code);
fclose($fh);
echo"File Updated and saved";


}
else{

if(isset($edit)){

$myFile = $edit;
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);

echo'
<form action="?act=edit2&edit=' . $edit . '" method="post">
<textarea name="code">' . $theData . '</textarea>
<br>
<input type="submit" value="Save File">
</form>';

}
else{

function dirList ($directory) {

	$content='';
	$dh = opendir($directory); 
	   while (false !== ($file = readdir($dh))) { 

		  if (!is_dir("$dirpath/$file") && $file!='error_log') { 

		   $content .= "<a href='?act=edit2&edit=" . $file . "'>" . htmlspecialchars(ucfirst(preg_replace('/\..*$/', '', $file))) . '</a><br>'; 
   } 
} 
	 closedir($dh);  

	echo $content;
}
dirList('.');

}
}

echo'</td>';

}
?>


How do I get it to remove the backslashes that were not manually typed into the box, or remove all backslahses and save the file without adding them in?

Is This A Good Question/Topic? 0
  • +

Replies To: How do I get rid of the \s

#2 snoj   User is offline

  • Married Life
  • member icon

Reputation: 93
  • View blog
  • Posts: 3,583
  • Joined: 31-March 03

Re: How do I get rid of the \s

Posted 02 October 2006 - 06:20 AM

stripslashes()
Was This Post Helpful? 0
  • +
  • -

#3 BetaWar   User is offline

  • #include "soul.h"
  • member icon

Reputation: 1651
  • View blog
  • Posts: 8,523
  • Joined: 07-September 06

Re: How do I get rid of the \s

Posted 02 October 2006 - 02:51 PM

Does that get rid of all slashes (front and back)? Or just the back? All I want to get rid of is the back slashes.
Was This Post Helpful? 0
  • +
  • -

#4 snoj   User is offline

  • Married Life
  • member icon

Reputation: 93
  • View blog
  • Posts: 3,583
  • Joined: 31-March 03

Re: How do I get rid of the \s

Posted 02 October 2006 - 05:01 PM

stripslashes() takes out slashes that are for escaping characters.
Was This Post Helpful? 0
  • +
  • -

#5 BetaWar   User is offline

  • #include "soul.h"
  • member icon

Reputation: 1651
  • View blog
  • Posts: 8,523
  • Joined: 07-September 06

Re: How do I get rid of the \s

Posted 02 October 2006 - 08:14 PM

Okay great, now I have a new question. How do I set a variable liek this:

$variable="<? $time[" . $log . "]='" . $time[now] . "'; $user[" . $log . "]='" . $user . "'; $msg[" . $log . "]='" . $msg . "'; $log=" . $log++ . "; ?>";



Without getting this error:

Parse error: syntax error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/reigning/public_html/chats/chatLog.php on line 23

What I am wanting to do is append a .php file so that I have added these variables into it. I want these variables to have a value (which is set by anoter variable in an array $log)
Was This Post Helpful? 0
  • +
  • -

#6 snoj   User is offline

  • Married Life
  • member icon

Reputation: 93
  • View blog
  • Posts: 3,583
  • Joined: 31-March 03

Re: How do I get rid of the \s

Posted 03 October 2006 - 12:30 PM

For starters, since you're using double quote marks ("), php is trying to parse the variable you have in the strings. So put a \ before the $ to stop it from doing that.

However, that isn't your problem. You see, you're leaving PHP code when you do "?>". Even if it's within a string, php still reads it and says, "oh! this is the end!" But it then sees the other one at the end of your file and get's confused.

So alls you need to do is break that up like so, $endStr = '?'.'>'; and your problem should just disappear like morning fog!
Was This Post Helpful? 0
  • +
  • -

#7 BetaWar   User is offline

  • #include "soul.h"
  • member icon

Reputation: 1651
  • View blog
  • Posts: 8,523
  • Joined: 07-September 06

Re: How do I get rid of the \s

Posted 03 October 2006 - 05:01 PM

Sweet thanks for that one :)

No yet another question (this one ajax related) How do I submit a form (post) without refreshing the page? I am making a chat which is working suprisingly well, but it has to refresh to post added content. I will post hte code I have if you want.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1