This may be a very simple question but I was unable to find the answer. There is a simple replacement:
$text = preg_replace("#\[title\](.*?)\[/title\]#si", "<span class=\"title\">\\1</span><a name=\"\\1\"></a>", $text);
The above code outputs:
<span class="title">Title One</span><a name="Title One"></a>
Now I want to remove space from the anchor so that it will be <a name="TitleOne">. To do so, I tried to use preg_replace inside preg_replace:
$text = preg_replace("#\[title\](.*?)\[/title\]#si", "<span class=\"title\">\\1</span><a name=\"" . preg_replace("/\s+/", "", "\\1") . "\"></a>", $text);
The problem is that it doesn't change anything and the space is still there. Could anyone be so kind and explain me what am I doing wrong? TIA.