Skip to content

Instantly share code, notes, and snippets.

@Drakekin
Created April 26, 2011 11:02
Show Gist options
  • Select an option

  • Save Drakekin/942112 to your computer and use it in GitHub Desktop.

Select an option

Save Drakekin/942112 to your computer and use it in GitHub Desktop.
Parsing for bug numbers with preg_replace
<?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