Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 24th, 2004, 06:19 AM
Registered User
 
Join Date: Jul 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to ghalebro Send a message via Yahoo to ghalebro
Default Regular expression problem

Hello

I have a problem of regular expression. I have a string which contains a pattern of backslash. I also Pattern Syntax of php mannual but i couldnot understand all the meanings and use of * ? ^ and so on.

my string goes like this.
$string = "logLx¿ h:t} c;+Vo dlxnf dL7fdL7f ;kgf lnP/ /fhwfgL cfp“5g\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ . o;af/] dlxnf cfof]unufotsf ;DalGwt lgsfo;“u jf:tljs tYofÍ klg 5}g . t/ klg cfkm\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\gf OR5f cfsf+Iff k\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"/f ug{ g;s]/ lg/fz ePsf dlxnfx¿sf] ;+Vof /fhwfgLdf a9\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\g yfn]sf] ;DalGwt If]qsf lj1x¿ atfp“5g\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ .

/fli6«o dlxnf cfof]usL cWoIf 8f= b\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'uf{ kf]v/]nn] klg /fhwfgLdf dlxnf /f]huf/Lsf] ;d:of lbg–k|ltlbg a9\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\b} uPsf] atfOg\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ . …cem aflx/af6 cfpg] dlxnfx¿ o;af6 cem a9L kLl8t 5g\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\Ú, pgn] elgg\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ . kf]v/]nn] dlxnf /f]huf/Lsf nflu ;/sf/n] …/f]huf/L k/fdz{ s]Gb|Ú vf]Ng\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'kg] ;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'emfj lbOg\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ .

…aflx/af6 cfPsf dlxnfx¿sf] JolQmTj ljsf;sf nflu dgf]j}1flgs k/fdz{ s]Gb| klg vf]Ng\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'k5{Ú, pgn] elgg\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\, …o:tf s]Gb|df pgLx¿n] ljrf/ cfbfg–k|bfg u5{g\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ . cfkm\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\gf] JolQmTj ;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'xfp“bf] /f]huf/ klxrfgsf] df}sf klg kfp“5g\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ .Ú cfof]un] klg o:tf s]Gb| :yfkgfsf nflu kxn ul//x]sf] hfgsf/L kf]v/]nn] lbOg\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ .";

and problem is I want to replace all the backslashes with "\\" or "\". can anyone tell me any resource or url related to this broblem or help me please.

Thank you


 
Old August 24th, 2004, 08:10 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, if you just want to replace all double backslashes with single ones....

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>String Thing</title>
</head>
<body>
<?php
$string = "logLx¿ h:t} c;+Vo dlxnf dL7fdL7f ;kgf lnP/ /fhwfgL cfp“5g\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ . o;af/] dlxnf cfof]unufotsf ;DalGwt lgsfo;“u jf:tljs tYofÍ klg 5}g . t/ klg cfkm\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\gf OR5f cfsf+Iff k\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"/f ug{ g;s]/ lg/fz ePsf dlxnfx¿sf] ;+Vof /fhwfgLdf a9\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\g yfn]sf] ;DalGwt If]qsf lj1x¿ atfp“5g\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ .";
$new_string = 'wibble';

while($new_string!=$string){
   $new_string = $string;
   $string = str_replace("\\\\","\\",$string);
}
echo $new_string;
?>
</body>
</html>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular Expression repeat problem Indo77 ASP.NET 2.0 Basics 1 May 28th, 2008 06:45 AM
Regular expression problem keyvanjan ASP.NET 2.0 Basics 0 May 28th, 2007 12:19 PM
Regular Expression escaping problem! nerssi Java Basics 1 June 14th, 2006 07:16 PM
regular expression problem muki XSLT 2 January 11th, 2006 06:04 AM
Regular Expression problem Mitch PHP How-To 2 May 14th, 2004 07:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.