View previous topic :: View next topic |
Author |
Message |
dkaye Smarty n00b
Joined: 04 Sep 2003 Posts: 4
|
Posted: Sat Sep 06, 2003 12:24 am Post subject: Escapes for single quotes? |
|
|
What's the best way to escape single quotes (apostrophes) to
& # 0 3 9 ; ? (spread out for display purposes)
The |escape modifier just prefaces a backslash. The application is within the string of a "value" attribute in an input form tag. You either need to escape the single or the double quotes, depending on which you don't use to define the value.
I'm using
| replace : " ' " : " & # 0 3 9 ; "
which works but it seems the built-in function should work, too. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Sat Sep 06, 2003 7:23 am Post subject: |
|
|
{$str|escape} or {$str|escape:html} should do what you want. for the possible different types of escape see the manual |
|
Back to top |
|
dkaye Smarty n00b
Joined: 04 Sep 2003 Posts: 4
|
Posted: Sat Sep 06, 2003 7:26 am Post subject: |
|
|
Nope. Those just insert (prepend) a backslash, which doesn't work within the VALUE attribute of an INPUT field. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Sat Sep 06, 2003 7:53 am Post subject: |
|
|
then you don't use the escape-modifier from the smarty-distribution. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Sat Sep 06, 2003 9:20 am Post subject: |
|
|
what version of smarty do you use?
how does the exact call to escape look like in your template?
for me this works:
{assign var=str value="'"}
{$str|escape}
{$str|escape:html}
{$str|escape:quotes}
{$str|escape:javascript}
it prints:
& #39 ;
& #39 ; [EDIT: spaces to prevent the forum from unescaping it]
\'
\'
Last edited by messju on Sat Sep 06, 2003 2:46 pm; edited 1 time in total |
|
Back to top |
|
dkaye Smarty n00b
Joined: 04 Sep 2003 Posts: 4
|
Posted: Sat Sep 06, 2003 12:46 pm Post subject: |
|
|
Must be an old age problem. I just attempt to re-create the problem, and I couldn't. It's working fine. What can I say?
"Never mind."
But thanks, messju!
(Doh!) |
|
Back to top |
|
charly71 Smarty Rookie
Joined: 10 Jun 2003 Posts: 6
|
Posted: Tue May 11, 2004 3:21 pm Post subject: |
|
|
How can I escape MS Word quotes like chr(146) and chr(147)? There is some plug-in that does this?
Thanks! |
|
Back to top |
|
charly71 Smarty Rookie
Joined: 10 Jun 2003 Posts: 6
|
Posted: Tue May 11, 2004 5:32 pm Post subject: |
|
|
charly71 wrote: | How can I escape MS Word quotes like chr(146) and chr(147)? There is some plug-in that does this?
Thanks! |
(I quote myself...)
Yes, you can!
Now you can use a powerful modifier called escape_wquotes I made...
Bye Bye... |
|
Back to top |
|
limbhg Smarty Regular
Joined: 18 Jun 2004 Posts: 62
|
Posted: Tue Jul 06, 2004 4:18 am Post subject: great 1 |
|
|
messju, you are great! i found this message is useful to solve my problem! i am done! thanks.
messju wrote: | what version of smarty do you use?
how does the exact call to escape look like in your template?
for me this works:
{assign var=str value="'"}
{$str|escape}
{$str|escape:html}
{$str|escape:quotes}
{$str|escape:javascript}
it prints:
& #39 ;
& #39 ; [EDIT: spaces to prevent the forum from unescaping it]
\'
\' |
|
|
Back to top |
|
|