Code:
function addLinks(){
preg_replace("text", "<a href=\"[URL]http://www.example.com/\">text</a[/URL]>", $spun, 1);
}
function addLinks(){
preg_replace("text", "<a href=\"[URL]http://www.example.com/\">text</a[/URL]>", $spun, 1);
}
function addLinks(){
preg_replace("/text/", "/<a href=\"[URL="http://www.example.com//%22%3Etext%3C/a%3E/"]http://www.example.com/\">text</a>/[/URL]", $spun, 1);
}
$spun = spinContent($spin_this);
$post = addLinks($spun);
echo $post
function addLinks($spun){
return preg_replace("/text/", "/<a href=\"http://www.example.com/\">text</a>/", $spun, 1);
}
$spun = spinContent($spin_this);
$post = addLinks($spun);
echo $post;
function addLinks( $spun ) {
$links = array( 'text' => 'link', 'moretext' => 'anotherlink' );
foreach( $links as $findMe => $link ) {
$spun = str_replace( $findMe, "<a href=\"$link\">$findMe</a>", $spun );
}
return $spun;
}
function addLinks( $spun ) {
$links = array( " text " => "[url=http://example.com/]Example Web Page[/url]", " here " => "[URL]http://otherexample.com/[/URL]" );
foreach( $links as $findMe => $link ) {
$counter = 1;
while ($counter>0) {
if ($counter==1) {
$spun = str_replace( $findMe, " <a href=\"$link\">$findMe</a> ", $spun );
$counter = $counter - 1;
}
}
}
return $spun;
}
<?php
class ALObj {
public $replacements = array( 'text' => 'link',
'moretext' => 'anotherlink' );
private $replaceIndex, $replacePointer;
function addLinks( $string ) {
foreach( $this->replacements as $findMe => $link ) {
preg_match_all( '/\s'.preg_quote( $findMe ).'\s/', $string, $matches );
if ( !isset( $matches[0][0] ) ) {
continue;
}
if ( ( $count = count( $matches[0] ) ) == 1 ) {
$this->replaceIndex = 0;
} else {
$this->replaceIndex = rand( 0, ( $count - 1 ) );
}
$this->replacePointer = 0;
$string = preg_replace_callback( '/\s'.preg_quote( $findMe ).'\s/', array( $this, 'checkReplacement' ), $string );
}
return $string;
}
function checkReplacement( $matches ) {
if ( $this->replaceIndex == $this->replacePointer ) {
$string = ' <a href="'.$this->replacements[ trim( $matches[0] ) ].'">'.trim( $matches[0] ).'</a> ';
} else {
$string = $matches[0];
}
++$this->replacePointer;
return $string;
}
}
$text = 'text ext random text weeerer text moretext text weee and then some moretext wee.';
$ALObj = new ALObj;
echo $ALObj->addLinks( $text );
?>