Running a function from within preg_replace in PHP
<p>I have a website which employs a PHP script to load some data from an HTML file and insert it in a link. So far it works perfectly:</p>

<pre><code>$html = preg_replace('/(\d+):(\d+),/', '&lt;a href="index.php?par1=$1&amp;amp;par2=$2"&gt;$1&amp;#58;$2&lt;/a&gt;,', $html);
</code></pre>

<p>Now I want to upgrade it to insert tooltips in the links. The data is loaded from a database and I have a special function <code>loadTooltip($param1, $param2)</code> that does the job. The problem is how to call the function from within <code>preg_replace()</code>. This is the code that I have but it doesn't run the data simply showing the name of the function with the parameters. This is the code:</p>

<pre><code>$html = preg_replace('/(\d+):(\d+),/', '&lt;a href="index.php?par1=$1&amp;amp;par2=$2" titel="loadTooltip($1, $2)"&gt;$1&amp;#58;$2&lt;/a&gt;,', $html);
</code></pre>

<p>So, how can I make it run?</p>
