kiwichick wrote:
It works great except for one problem - when & is entered in either field:
That is because the "&" sign is used by the HTML protocol
to delimiter the different returned parts:
?Search=THIS&Replace=THAT&Rename= Replace
?Search=THIS & Replace=THAT & Rename= Replace
If your script now return an "&" you end up with two "&"
and so gettoken() takes the wrong one:
?Search=&&Replace=&&Rename= Replace
?Search=& & Replace=& & Rename= Replace
Add a "step;" command and watch the debugger to spot the issue.
One way would be, like highend posted, a other method to get the result from the html() command return.
Another way would be, if you like the step-by-step method and dislike regex,
to mask the "&" signs with an uncommon temporary-replacement-sign.
Code: Select all
"Replacer|:rename"
end(getinfo("CountSelected") < 1), "Nothing selected!";
$html = urldecode(html('
<html>
<body style="font-family:arial;">
<form method="get" action="xys:">
Replace This: <INPUT TYPE="TEXT" NAME="Search" SIZE="60" VALUE=""><BR>
With This: <INPUT TYPE="TEXT" NAME="Replace" SIZE="60" VALUE=""> <BR>
<p align="left"><INPUT type="submit" name="Rename" value=" Replace " ></p>
</form>
</body>
</html>',"480", "260", "Renamer"));
// step; // open the debugger
//mask the &-sign and the following button-id with an temporary string:
$html = replace($html,"&Replace", ">DELIM<Replace");
$html = replace($html,"&Rename", ">DELIM<Rename");
//replace every remained "&" with an temporary replacement string:
$html = replace($html,"&", ">ATSIGN<");
//rename the "&" plus button-id back to origin string:
$html = replace($html,">DELIM<Replace", "&Replace");
$html = replace($html,">DELIM<Rename", "&Rename");
//Now gettoken() have a change to correctly split the returned string at the "&" signs as always:
$Search = gettoken($html, "1", "&");
$Replace = gettoken($html, "2", "&");
$Search = gettoken($Search, "2", "=");
$Replace = gettoken($Replace, "2", "=");
//at the end, replace the temporary replacement of the "&" back to the origin "&" sign:
$Search = replace($Search,">ATSIGN<", "&");
$Replace = replace($Replace,">ATSIGN<", "&");
// rename s, "$Search/$Replace";
text "$Search/$Replace";
Result debugging:
User input:
Replace: This&This
With: That&That
replace()
----
?Search=This&This&Replace=That&That&Rename= Replace
----
&Replace
----
>DELIM<Replace
set
----
$html
----
?Search=This&This>DELIM<Replace=That&That&Rename= Replace
Results in:
This&This/That&That