I have a string like this:
$string = "This is my name: David";
And I want to turn it into this:
This is my name: <a href="https://www.example.com?q=David">David</a>
Means:
Get everything between "name: " (first delimiter) and the end of the string (second delimiter).
Set </a> after the extracted string (in this case "David").
Set <a href="https://www.example.com?q="> in front of the extracted string (in this case "David").
Insert the extracted string (in this case "David") after "q=" like: q=David
I'm good in PHP but I always stuck with regular expressions.
Is the anybody who can help me to do this?
EDIT:
This is what I have so far:
<?php
$string = "This is my name: David";
if(stripos($string, "name: ") !== false) {
$string = str_replace("name: ", "<a href=\"https://www.example.com?q=\">", $string);
$string = implode(array($string, "</a>"));
}
echo $string;
?>