FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » not understanding pattern matching
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: not understanding pattern matching [message #178620 is a reply to message #178614] Fri, 13 July 2012 03:22 Go to previous messageGo to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma:
Senior Member
On Wed, 11 Jul 2012 19:31:12 -0400, Michael Joel wrote:

> I was trying to just first get it to replace the exact thing typed. Then
> move on to replacing any word within the %/i% and %i%
>
> $Scripture="this is a %/i%test%i%";
> preg_replace("%/i%test%i%","XXXXXXXX",$Scripture);
>
> This errors with Unknown modifier t I tried what I thought was escaping
> it by putting a \test but that just messes up more. See I haven't a
> clue.

http://php.net/manual/en/regexp.reference.delimiters.php

When you use a regex, the first character inside your quotes is taken as
the pattern delimiter.

In your case, this is a "%" character.

The format of a regex string is:

"delimiter pattern delimiter optional-modifiers"

Hence, "%/i%t" is the pattern "/i" with the modifier "t"

Try:

preg_replace("!%/i%test%i%!","XXXXXXXX",$Scripture);

This will use the "!" character as the pattern delimiter and should, in
this specific case, solve your problem. Generally it's a good idea to
pick a pattern delimiter that does not have special meaning to regex and
is not part of your data. This isn't always easy.

Rgds

Denis McMahon
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Check out www.phpscribble.com
Next Topic: Lost $_SESSION in Google Chrome
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 13:47:41 GMT 2024

Total time taken to generate the page: 0.04393 seconds