I am attempting to allow users to link to other wallposts within their own wallposts. so for example if user types: Please see post ::35 for more information I would change the string to: Please see <a href="posts/35">35</a>
for more information
I have the following function which grabs all the post numbers from the content, as denoted by :: at the beginning.
function getBetween($content, $start, $end, $rest = array()) {
$r = explode($start, $content, 2);
if (isset($r[1])) {
$r = explode($end, $r[1], 2);
$rest[] = $r[0];
return getBetween($r[1], $start, $end, $rest);
} else {
return $rest;
}
}
$post = 'Lorem ::35 ipsum ::36 dolor sit ::37 ::38';
$links = getBetween($post, '##', ' ');
$links returns an array containing 35, 36, 37, 38. What I don't know is how I can replace them in the original string with the hyperlinks.