Created
September 15, 2010 14:32
-
-
Save Achillefs/580808 to your computer and use it in GitHub Desktop.
This file contains 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 | |
class Phrase { | |
public static function to_link($content){ | |
$phrases = DbFinder::from("Phrase")->find(); # This was for a symfony site | |
foreach ($phrases as $p) { # Interestingly, foreach is much faster than a for loop | |
$text = preg_quote($p->getText()); # Sanitize the text | |
$content = preg_replace("/(?!=(?:<a [^>]*>))({$text})(?!(?:<\/a>))/si","<a href=\"{$p->getUrl()}\">\\1</a>",$content,1); | |
} | |
return $content; | |
} | |
} ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment