1

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:

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

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 loadTooltip($param1, $param2) that does the job. The problem is how to call the function from within preg_replace(). 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:

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

So, how can I make it run?

1

1 Answer 1

3

You can use preg_replace_callback for the task.

You might have to edit the output string of your function a bit.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.