I have just started with PHP regular expression. I understand how to read and write them (I need my book because I do not remember the symbols of any pattern). I really want to use RegExp for BB code on my site using the I understand the standards, but I do not understand what defines can be changed in the pattern? What I've done so far: Now, I know that this is probably not "intelligent" security, I just want to do some work. I match the entire string ... so I get a link which is I defined the PHP manual I do not even know what is said to them. Has anyone explained this to me? One replacement without errors: 1) Pattern 2) Replacement Optional :, see the first example. preg_replace
preg_replace ('/ (\ [url = http: \ / \ /.* \]) /', '& lt; a href = "$ 1 "& Gt; $ 2 & lt; / a & gt; '," [url = http: //google.com] ");
mysite / [url = http: //google.com] . looks like.
$ bibilink = ' [Url = http: //google.com] '; $ Pattern = '~ \ [url = (http: // [^]] +)] ~'; $ Replacement = '& lt; A href = "$ 1" & gt; $ 1 & lt; / A & gt; '; $ Result = preg_replace ($ pattern, $ replacement, $ bibilink); Explanation:
~ # pattern delimiter \ [# Textual opening square bracket URL = (# Capturing first Group http: // [^]] + # all letters that are not one place or one or more times # Close the capturing group # Textual ending square bracket ~ # pattern delimiter
$ 1 First refer to the capturing group
No comments:
Post a Comment