[PHP (fixed)] replace slash (/) with slash (%2F)

Joined
Jun 8, 2007
Messages
1,961
Reaction score
475
I have this manual code editor for my site that allows me to edit pages, and it has trouble updating pages that are inside folders. The problem is that the path to the file is stored in the URL using the GET method, and you can't have any slashes inside a query string. All slashes in the URL that aren't supposed to be there are translated to %2F.

Problem: When PHP echo's %2F, it converts to a slash(/) in the HTML code.

In a GET method form, if a slash(/) is used in an input it gets converted to %2F to conserve the URL.
When you call for the var in PHP, it gets converted back to a slash(/) to conserve the value.
This system is pretty smart and works good in most cases.
However, in the second stage there is a POST method form to actually update the content. The only way I found to keep the $_GET variables is to make the action of the form like below:
PHP:
<form name="changeContent" method="post" action="manual_edit.php?pageURL=<?php echo $thisPage; ?>" >
and it outputs this:
PHP:
<form name="changeContent" method="post" action="manual_edit.php?pageURL=tutorial/browser.php" >

I want it to output this
PHP:
<form name="changeContent" method="post" action="manual_edit.php?pageURL=tutorial%2Fbrowser.php" >
I tried doing str_replace in PHP but that didn't work because it just gets transformed back into a slash(/) :/

Any Ideas? :blush:
 
Last edited:
Back