Created
April 26, 2011 11:02
-
-
Save Drakekin/942112 to your computer and use it in GitHub Desktop.
Parsing for bug numbers with preg_replace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $pattern = "/(#)([0-9]+)/"; | |
| $replace = "<a href='http://mysite.com/bug/$2/'>#$2</a>"; | |
| $text = "The bug #40 was replaced fixed, but then caused bug #87 and #89. I think we fixed it when we caused bug #212 though."; | |
| echo preg_replace($pattern, $replace, $text); | |
| ?> | |
| <!-- | |
| Output: | |
| The bug <a href='bug/40/'>#40</a> was replaced fixed, but then caused bug <a href='bug/87/'>#87</a> and <a href='bug/89/'>#89</a>. I think we fixed it when we caused bug <a href='bug/212/'>#212</a> though. | |
| --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment