RE: escaping characters

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Try two preg_replace functions.  Use the following patterns in the first to
match:

'/(\\\')/' replacing with a single quote. 

Use the following pattern for the second function:

'/\\\"/' replacing with a double quote.  If this one does not work, leave
our the third backslash in the pattern.

This should match only combinations of back slashes and single or double
quote marks.  You can run the function so that the result returns to the
subject, as in:

$subject = preg_replace('/\\\'/',"'",$subject);

Let me know if this works.



gentlemike2



-----Original Message-----
From: php-objects@xxxxxxxxxxxxxxx [mailto:php-objects@xxxxxxxxxxxxxxx] On
Behalf Of steve miller
Sent: Sunday, June 13, 2010 11:17 AM
To: php-objects@xxxxxxxxxxxxxxx
Subject: Re:  escaping characters

But if I use stripslashes, won't I get something like

echo "I'm "cool"";

which would not work?



On Jun 13, 2010, at 10:45 AM, Davide Baglieri wrote:

> Just use stripslashes function.
>
> Il giorno 13/giu/2010, alle ore 16.09, steve miller <steve@xxxxxxxxxx>
> ha scritto:
>
> > Oops; wasn't complete in my question!
> >
> > I don't have a problem in browsers because they ignore the backslash
> > if I leave it in.
> > The problem is when I am creating an email because the email
> > applications don't ignore the backslash, but show it as \" or \'  
> so I
> > have to remove them.
> >
> >
> > Steve
> >
> >
> >
> > On Jun 13, 2010, at 9:49 AM, steve miller wrote:
> >
> >> I have a simple but perplexing problem I could use some help with.
> >>
> >> I am storing user text input strings in mysql, and am escaping '  
> and
> >> " with addslashes.
> >> When I pull them out and use stripslashes, I sometimes get errors
> >> because I don't know if they have a ' or a " in the string.
> >>
> >> Example 1
> >> String is: I'm cool
> >> This works: echo "I'm cool";
> >> This does not: echo 'I'm cool';
> >>
> >> Example 2
> >> String is: You are "cool"
> >> This works: echo 'You are "cool"';
> >> This does not: echo "You are "cool"";
> >>
> >> Example 3
> >> String is: I'm "cool"
> >> This does not work: echo "I'm "cool"";
> >> This does not work: echo 'I'm "cool"';
> >>
> >> So, how do I output strings of unknown content?
> >>
> >> Thanks for any guidance.
> >>
> >> Steve
> >>
> >
> >
> >
> > [Non-text portions of this message have been removed]
> >
> >
> >
> > ------------------------------------
> >
> > Are you looking for a PHP job?
> > Join the PHP Professionals directory Now!
> > http://www.phpclasses.org/jobs/
> > Yahoo! Groups Links
> >
> >
> >
> 



[Non-text portions of this message have been removed]



------------------------------------

Are you looking for a PHP job?
Join the PHP Professionals directory Now!
http://www.phpclasses.org/jobs/
Yahoo! Groups Links




[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux