Hello,
I'm having trouble figuring out the syntax for my replacement.
The goal is to insert Wikipedia links at the bottom of articles. I've been given a spreadsheet with different entries for each article (hundreds, close to 1000 entries.)
My idea is to enter them as an expression to be replaced e.g.
Code:
{wp = The Beatles, Liverpool, John Lennon, Paul McCartney, George Harrison, Ringo Starr}
And generate the output:
Code:
<ul>
<li><a href="https://en.wikipedia.org/wiki/The Beatles" target="_blank">The Beatles</a></li>
<li><a href="https://en.wikipedia.org/wiki/Liverpool" target="_blank">Liverpool</a></li>
<li><a href="https://en.wikipedia.org/wiki/John Lennon" target="_blank">John Lennon</a></li>
<li><a href="https://en.wikipedia.org/wiki/Paul McCartney" target="_blank">Paul McCartney</a></li>
<li><a href="https://en.wikipedia.org/wiki/George Harrison" target="_blank">George Harrison</a></li>
<li><a href="https://en.wikipedia.org/wiki/Ringo Starr" target="_blank">Ringo Starr</a></li>
</ul>
From the spreadsheet, I can enter them through a query to the appropriate article, that's not a problem.
I'm failing on creating the replacer code.
I'm using PHP to split the expressions using the commas (,) and create the output, which works fine as PHP but I can't get it to work in the replacer
In the 'From' box I've tried (with REGEXP and Code (PHP) on) :
And the PHP code that works is:
Code:
<?php
$keywords = preg_split("/[,]+/", $1);
$textoutput = "<ul>";
foreach ($keywords as $link) {
$link = ltrim($link);
$textoutput .= "<li><a href='https://en.wikipedia.org/wiki/" . $link . "' target=_blank >" . $link . "</a></li>";
}
$textoutput .= "</ul>";
echo $textoutput;
?>
How can I get this to work?
Thank you!
Tomás