prometheuzz wrote:Hard to say without seeing the input string. Can you post it?
Also post what the desired result should be and what result you are currently getting.
sure thing. Here's the Input String:
Code: Select all
<p> test</p><p>test</p><p>blah</p><p>ok</p><p>test test >test< blah</p><p>blahokblah </p><p> </p><p>blahsirdir</p><p>blabergasted</p><p>backok </p>
output:
Code: Select all
<p> <a href = "http://www.theprogressiveaccountant.com"><a href = "http://www.theprogressiveaccountant.com"><a href = "http://www.theprogressiveaccountant.com"><a href = "http://www.theprogressiveaccountant.com"><a href = "http://www.theprogressiveaccountant.com">test</a></a></a></a></a></p><p><a href = "http://www.theprogressiveaccountant.com"><a href = "http://www.theprogressiveaccountant.com"><a href = "http://www.theprogressiveaccountant.com"><a href = "http://www.theprogressiveaccountant.com"><a href = "http://www.theprogressiveaccountant.com">test</a></a></a></a></a></p><p><a href = "http://www.pmgb2b.com"><a href = "http://www.pmgb2b.com">blah</a></a></p><p><a href = "http://www.yahoo.com"><a href = "http://www.yahoo.com">ok</a></a></p><p><a href = "http://www.theprogressiveaccountant.com"><a href = "http://www.theprogressiveaccountant.com"><a href = "http://www.theprogressiveaccountant.com"><a href = "http://www.theprogressiveaccountant.com"><a href = "http://www.theprogressiveaccountant.com">test</a></a></a></a></a> <a href = "http://www.theprogressiveaccountant.com"><a href = "http://www.theprogressiveaccountant.com"><a href = "http://www.theprogressiveaccountant.com"><a href = "http://www.theprogressiveaccountant.com"><a href = "http://www.theprogressiveaccountant.com">test</a></a></a></a></a> ><a href = "http://www.theprogressiveaccountant.com"><a href = "http://www.theprogressiveaccountant.com"><a href = "http://www.theprogressiveaccountant.com"><a href = "http://www.theprogressiveaccountant.com"><a href = "http://www.theprogressiveaccountant.com">test</a></a></a></a></a>< <a href = "http://www.pmgb2b.com"><a href = "http://www.pmgb2b.com">blah</a></a></p><p><a href = "http://www.pmgb2b.com"><a href = "http://www.pmgb2b.com">blah</a></a><a href = "http://www.yahoo.com"><a href = "http://www.yahoo.com">ok</a></a><a href = "http://www.pmgb2b.com"><a href = "http://www.pmgb2b.com">blah</a></a> </p><p> </p><p><a href = "http://www.pmgb2b.com"><a href = "http://www.pmgb2b.com">blah</a></a>sirdir</p><p>blabergasted</p><p>back<a href = "http://www.yahoo.com"><a href = "http://www.yahoo.com">ok</a></a> </p>
as you can see, it's applying the links to each pattern multiple times, which was not what I was trying to do
and here's the code which I'm working on.
Code: Select all
class plgContentLinkplugin extends JPlugin
{
public function onPrepareContent(&$article, &$params, $limitstart)
{
global $mainframe;
$content = $article -> text;
$keywords = $this -> params->def('keywords');
$words = explode(",", $keywords);
$keywordLinks = $this -> params->def('links');
$Links = explode(",", $keywordLinks);
$number = count($words);
for($x = 0; $x <= count($words); $x++)
{
if(preg_match_all("/\b".$words[$x]."\b/i", $content, $matches))
{
foreach($matches[0] as $change)
{
$content = str_replace($change, str_replace($words[$x], '<a href = "'.$Links[$x].'">'.$words[$x].'</a>', $change), $content);
}
}
}
$article -> text = $content;
}
}