Re: [PHP] Deleting multiple backslashes; regex?

2010-03-16 Thread Al



On 3/15/2010 5:03 PM, Jim Lucas wrote:

Al wrote:

Anyone have a regex pattern for deleting multiple backslashes e.g., \\\

I pretty good with regex; but, be damned if I can delete them with
preg_replace()

I've tried "" as the manual says

preg_replace("//", '', $str);

preg_replace("/()+/", '', $str);

preg_replace("/\x5C/", '', $str);

preg_replace("/\\x5c/", '', $str);

And lots of others.

stripslashes() and stripcslashes() are limited.





Might I ask, how are the multiple slashes getting generated in the first place?
  Where is the data coming from?

Next question would be: Do you want to completely remove all instances of
multiple backslashes?  Or, do you want to replace all instances of multiple
backslashes with a single backslash?

I would try something like this:


done!




As I reported earlier, problem was my code was reloading a POST array following 
the backlash removal. Dumb error on my part.


Re: "Might I ask, how are the multiple slashes getting generated in the first 
place? Where is the data coming from?"  It comes from a client-side editor where 
users can enter them at will. It is my standard practice to do a good job of 
protecting users from themselves. I originally just had the usual stripslashes() 
but found it didn't take care of users adding several.



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Deleting multiple backslashes; regex?

2010-03-15 Thread Jim Lucas
Al wrote:
> Anyone have a regex pattern for deleting multiple backslashes e.g., \\\
> 
> I pretty good with regex; but, be damned if I can delete them with
> preg_replace()
> 
> I've tried "" as the manual says
> 
> preg_replace("//", '', $str);
> 
> preg_replace("/()+/", '', $str);
> 
> preg_replace("/\x5C/", '', $str);
> 
> preg_replace("/\\x5c/", '', $str);
> 
> And lots of others.
> 
> stripslashes() and stripcslashes() are limited.
> 
> 
> 

Might I ask, how are the multiple slashes getting generated in the first place?
 Where is the data coming from?

Next question would be: Do you want to completely remove all instances of
multiple backslashes?  Or, do you want to replace all instances of multiple
backslashes with a single backslash?

I would try something like this:


done!


-- 
Jim Lucas
NOC Manager
541-323-9113
BendTel, Inc.
http://www.bendtel.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Deleting multiple backslashes; regex?

2010-03-15 Thread Al



On 3/15/2010 3:30 PM, Ashley Sheridan wrote:

On Mon, 2010-03-15 at 15:35 -0400, Al Rider wrote:




On 3/15/2010 3:11 PM, Ashley Sheridan wrote:


On Mon, 2010-03-15 at 15:03 -0400, Al wrote:


Anyone have a regex pattern for deleting multiple backslashes e.g., \\\

I pretty good with regex; but, be damned if I can delete them with 
preg_replace()

I've tried "" as the manual says

preg_replace("//", '', $str);

preg_replace("/()+/", '', $str);

preg_replace("/\x5C/", '', $str);

preg_replace("/\\x5c/", '', $str);

And lots of others.

stripslashes() and stripcslashes() are limited.







What about this:

$str = 'text\\dfnfg\\dhdsg';
echo preg_replace('/\\\{2,}/', '', $str);

I think what was catching you out was that you were escaping the \
once for the regex, but then it needed it again because it was in a
single quoted string, meaning 3 slashes in total. Took me a little
while to figure that out as well!

The {2,} part just tells it to only remove the slashes where they
occur in runs of two or more.




I agree, it should work; but, it doesn't.

Most everything that looks reasonable works in The Regex Coach,
including you suggestion.

I'm starting to think there is a bug in the regex engine; haven't
looked yet.  It's doubtful though because the bug would screw existing
code.


Thanks,
Ash
http://www.ashleysheridan.co.uk






I tried the code I just gave you and it's working, so I'm not sure now
what issue you're having with it?

Thanks,
Ash
http://www.ashleysheridan.co.uk





Thanks ever so much guys. Sometimes it's helpful when someone else confirms 
something must work.


Problem was that I had a series of cleanup and security checks on a POST array 
and inadvertently used the original POST array in one of the steps following the 
backslash remove step, so obviously it didn't work.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Deleting multiple backslashes; regex?

2010-03-15 Thread james stojan
Double check your code I came up with the same solution as Ash did and it
worked fine in Wamp.

On Mon, Mar 15, 2010 at 3:30 PM, Ashley Sheridan
wrote:

> On Mon, 2010-03-15 at 15:35 -0400, Al Rider wrote:
>
> >
> >
> > On 3/15/2010 3:11 PM, Ashley Sheridan wrote:
> >
> > > On Mon, 2010-03-15 at 15:03 -0400, Al wrote:
> > >
> > > > Anyone have a regex pattern for deleting multiple backslashes e.g.,
> \\\
> > > >
> > > > I pretty good with regex; but, be damned if I can delete them with
> preg_replace()
> > > >
> > > > I've tried "" as the manual says
> > > >
> > > > preg_replace("//", '', $str);
> > > >
> > > > preg_replace("/()+/", '', $str);
> > > >
> > > > preg_replace("/\x5C/", '', $str);
> > > >
> > > > preg_replace("/\\x5c/", '', $str);
> > > >
> > > > And lots of others.
> > > >
> > > > stripslashes() and stripcslashes() are limited.
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> > > What about this:
> > >
> > > $str = 'text\\dfnfg\\dhdsg';
> > > echo preg_replace('/\\\{2,}/', '', $str);
> > >
> > > I think what was catching you out was that you were escaping the \
> > > once for the regex, but then it needed it again because it was in a
> > > single quoted string, meaning 3 slashes in total. Took me a little
> > > while to figure that out as well!
> > >
> > > The {2,} part just tells it to only remove the slashes where they
> > > occur in runs of two or more.
> > >
> >
> >
> > I agree, it should work; but, it doesn't.
> >
> > Most everything that looks reasonable works in The Regex Coach,
> > including you suggestion.
> >
> > I'm starting to think there is a bug in the regex engine; haven't
> > looked yet.  It's doubtful though because the bug would screw existing
> > code.
> >
> > > Thanks,
> > > Ash
> > > http://www.ashleysheridan.co.uk
> > >
> > >
> > >
>
>
> I tried the code I just gave you and it's working, so I'm not sure now
> what issue you're having with it?
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>


Re: [PHP] Deleting multiple backslashes; regex?

2010-03-15 Thread Ashley Sheridan
On Mon, 2010-03-15 at 15:35 -0400, Al Rider wrote:

> 
> 
> On 3/15/2010 3:11 PM, Ashley Sheridan wrote: 
> 
> > On Mon, 2010-03-15 at 15:03 -0400, Al wrote: 
> > 
> > > Anyone have a regex pattern for deleting multiple backslashes e.g., 
> > > \\\
> > > 
> > > I pretty good with regex; but, be damned if I can delete them with 
> > > preg_replace()
> > > 
> > > I've tried "" as the manual says
> > > 
> > > preg_replace("//", '', $str);
> > > 
> > > preg_replace("/()+/", '', $str);
> > > 
> > > preg_replace("/\x5C/", '', $str);
> > > 
> > > preg_replace("/\\x5c/", '', $str);
> > > 
> > > And lots of others.
> > > 
> > > stripslashes() and stripcslashes() are limited.
> > > 
> > > 
> > > 
> > > 
> > 
> > 
> > What about this:
> > 
> > $str = 'text\\dfnfg\\dhdsg';
> > echo preg_replace('/\\\{2,}/', '', $str);
> > 
> > I think what was catching you out was that you were escaping the \
> > once for the regex, but then it needed it again because it was in a
> > single quoted string, meaning 3 slashes in total. Took me a little
> > while to figure that out as well!
> > 
> > The {2,} part just tells it to only remove the slashes where they
> > occur in runs of two or more.
> > 
> 
> 
> I agree, it should work; but, it doesn't.  
> 
> Most everything that looks reasonable works in The Regex Coach,
> including you suggestion.  
> 
> I'm starting to think there is a bug in the regex engine; haven't
> looked yet.  It's doubtful though because the bug would screw existing
> code.  
> 
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> > 
> > 
> > 


I tried the code I just gave you and it's working, so I'm not sure now
what issue you're having with it?

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Deleting multiple backslashes; regex?

2010-03-15 Thread Ashley Sheridan
On Mon, 2010-03-15 at 15:03 -0400, Al wrote:

> Anyone have a regex pattern for deleting multiple backslashes e.g., \\\
> 
> I pretty good with regex; but, be damned if I can delete them with 
> preg_replace()
> 
> I've tried "" as the manual says
> 
> preg_replace("//", '', $str);
> 
> preg_replace("/()+/", '', $str);
> 
> preg_replace("/\x5C/", '', $str);
> 
> preg_replace("/\\x5c/", '', $str);
> 
> And lots of others.
> 
> stripslashes() and stripcslashes() are limited.
> 
> 
> 


What about this:

$str = 'text\\dfnfg\\dhdsg';
echo preg_replace('/\\\{2,}/', '', $str);

I think what was catching you out was that you were escaping the \ once
for the regex, but then it needed it again because it was in a single
quoted string, meaning 3 slashes in total. Took me a little while to
figure that out as well!

The {2,} part just tells it to only remove the slashes where they occur
in runs of two or more.

Thanks,
Ash
http://www.ashleysheridan.co.uk




[PHP] Deleting multiple backslashes; regex?

2010-03-15 Thread Al

Anyone have a regex pattern for deleting multiple backslashes e.g., \\\

I pretty good with regex; but, be damned if I can delete them with 
preg_replace()

I've tried "" as the manual says

preg_replace("//", '', $str);

preg_replace("/()+/", '', $str);

preg_replace("/\x5C/", '', $str);

preg_replace("/\\x5c/", '', $str);

And lots of others.

stripslashes() and stripcslashes() are limited.



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php