I am having a hard time figuring this out:
I have a string ($data) which contains some links formatted this way:
[pagelink]Folder/File[/pagelink]
The $data contains multiple of these links.
I need to replace these links with actual html links and I have this code to do it (which works):
$data = preg_replace('/\[pagelink\](.*?)\[\/pagelink\]/is','<a href="$1">$1</a>',$data);
Now I would like to remove all the "Folder" instances from the part of the link that is showed to the user without actually altering the link itself; in other words if the link is this:
[pagelink]Folder/File[/pagelink]
I would like it to become this:
<a href="Folder/File">File</a>
What I tried is this:
$data = preg_replace('/\[pagelink\](.*?)\[\/pagelink\]/is','<a href="$1">'.( strstr($1) === false ? $1 : str_replace('/','',strstr($1)) ).'</a>',$data);
but I get a bunch of errors so I guess I can't use back references this way.
Could you guys help me out please? Thanks