Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Escapes for single quotes?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
dkaye
Smarty n00b


Joined: 04 Sep 2003
Posts: 4

PostPosted: Sat Sep 06, 2003 12:24 am    Post subject: Escapes for single quotes? Reply with quote

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
View user's profile Send private message Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Sat Sep 06, 2003 7:23 am    Post subject: Reply with quote

{$str|escape} or {$str|escape:html} should do what you want. for the possible different types of escape see the manual
Back to top
View user's profile Send private message Send e-mail Visit poster's website
dkaye
Smarty n00b


Joined: 04 Sep 2003
Posts: 4

PostPosted: Sat Sep 06, 2003 7:26 am    Post subject: Reply with quote

Nope. Those just insert (prepend) a backslash, which doesn't work within the VALUE attribute of an INPUT field.
Back to top
View user's profile Send private message Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Sat Sep 06, 2003 7:53 am    Post subject: Reply with quote

then you don't use the escape-modifier from the smarty-distribution.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Sat Sep 06, 2003 9:20 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
dkaye
Smarty n00b


Joined: 04 Sep 2003
Posts: 4

PostPosted: Sat Sep 06, 2003 12:46 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
charly71
Smarty Rookie


Joined: 10 Jun 2003
Posts: 6

PostPosted: Tue May 11, 2004 3:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
charly71
Smarty Rookie


Joined: 10 Jun 2003
Posts: 6

PostPosted: Tue May 11, 2004 5:32 pm    Post subject: Reply with quote

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...) Laughing

Yes, you can!

Now you can use a powerful modifier called escape_wquotes I made...

Bye Bye...
Back to top
View user's profile Send private message
limbhg
Smarty Regular


Joined: 18 Jun 2004
Posts: 62

PostPosted: Tue Jul 06, 2004 4:18 am    Post subject: great 1 Reply with quote

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
View user's profile Send private message Yahoo Messenger
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP