Special Characters in a variable

Post Reply
source1ben
Posts: 32
Joined: Fri Nov 02, 2001 10:22 am

Special Characters in a variable

Post by source1ben »

I need to convert several special characters and pass them in a variable. I am trying to perform a <sandr> but it doesn't seem to work. Here is an example of some of the characters.

<sandr "<" "<" $iso_in>
<sandr ">" ">" $ret>
<sandr "\&" "&" $ret>
<sandr '\"' '"' $ret>
<sandr "'" "&apos;" $ret>
<sandr "¡" "&iexcl;" $ret>
<sandr "¢" "&cent;" $ret>
<sandr "£" "&pound;" $ret>
<sandr "¤" "&curren;" $ret>
<sandr "¥" "&yen;" $ret>
<sandr "¦" "&brvbar;" $ret>
<sandr "§" "&sect;" $ret>
<sandr "¨" "&uml;" $ret>
<sandr "©" "&copy;" $ret>
.
.
.etc..

Can this be done with rex? I tried using fmt & send but I was unable to get my output into a variable. I also tried loading them into a table, however, the characters were converted to something else when I performed the insert.

I'm sure there's more than one way to handle it - just looking for the best method for maintenance, maintainability, structure, etc...
User avatar
Kai
Site Admin
Posts: 1272
Joined: Tue Apr 25, 2000 1:27 pm

Special Characters in a variable

Post by Kai »

<strfmt> will output into $ret instead of printing like <fmt> does. The characters aren't converted when loaded; the only automatic translation occurs when you _print_ a variable in the default (HTML) mode: its contents will be HTML-escaped since the content type is HTML. But the variable's value remains the same. See http://www.thunderstone.com/site/vortexman/node11.html. To avoid escaping HTML characters when printing, use <fmt "%s" $val> or <send $val>.

<strfmt "%H" $iso_in> followed by several <sandr> calls for the currency, etc. symbols is probably best.
User avatar
mark
Site Admin
Posts: 5519
Joined: Tue Apr 25, 2000 6:56 pm

Special Characters in a variable

Post by mark »

Also, when <sandr>ing a number of items it's more efficient to do it with one call:
<$search="§" "¨" "©">
<$replace="&sect;" "&uml;" "&copy;">
<sandr $search $replace $data>
Post Reply